For loops

Demonstrate the for loop in Ruby.

Solution

array = [1, 2, 3, 4, 5]
for i in array
    puts i
end
Run this

Explanation

Iterating using the construct for x in container will iterate through the values of the array.

Comments by Disqus