ruby array for each code example
Example 1: ruby each array
a = [ "a", "b", "c" ]
a.each {|x| print x, " -- " }
Example 2: iterate over array ruby
# For Ruby
arr = ['a', 'b', 'c']
arr.each { |item| puts item }
Example 3: ruby loop through array
numbers = [0, 1, 2, 3]
for element in numbers do
puts element
end
Example 4: ruby how to loop through an array
array = [1, 2, 3, 4, 5, 6]
array.each { |x| puts x }