How to iterate an array in ruby

array = [1, 2, 3, 4, 5, 6]
array.each { |x| puts x }

Do we have any other way to iterate?

Why are you asking this?

The enumerator module is very useful, but also see loops in documentation:

for x in array
  puts x
end
2 Likes