Learn
Loops & Iterators

Try It Out!

Cool, no? Now it's your turn to take the .each method for a test drive.

numbers = [1, 2, 3, 4, 5]

# one way to loop
numbers.each { |item| puts item }

# another way to loop
numbers.each do |item|
  puts item
end
  1. In the example above, we create an array called numbers.
  2. Then we show two different ways to print each item in numbers to the console.
Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.