Use an upto Iterator to reference array element : upto « Statement « Ruby






Use an upto Iterator to reference array element


fruits = ["peaches", "pumpkins", "apples", "oranges"]
    
print "We offer "
    
0.upto(fruits.length - 1) do |loop_index|
  print fruits[loop_index] + " "
end

 








Related examples in the same category

1.use the upto iterator, which is what traditional for loops translate into in Ruby.
2.uses the upto iterator to create a loop similar to a for loop from other languages
3.use curly braces ({}):
4.The upto Method and for loop
5.Example of upto that prints out a times table for 2
6.do all the times tables from 1 to 12
7.One date may upto another
8.Interpolation with upto and array
9.upto with / without {}