Code Editor
Learn
Data Structures

Iterating Over Arrays

Iterating over arrays is easier than it looks.

numbers = [1, 2, 3, 4, 5] numbers.each { |element| puts element }
  1. In the example above, we create an array called numbers with 5 elements.
  2. Then we say, "Take this array and for each element, print it to the console." As usual, we can use any placeholder name for the bit between two | | characters.
Report a Bug
If you see a bug or any other issue with this page, please report it here.