use the upto iterator, which is what traditional for loops translate into in Ruby. : upto « Statement « Ruby






use the upto iterator, which is what traditional for loops translate into in Ruby.


grades = [88, 99, 73, 56, 87, 64]

sum = 0

0.upto(grades.length - 1) do |loop_index|
  sum += grades[loop_index]
end

average = sum / grades.length

puts average

 








Related examples in the same category

1.Use an upto Iterator to reference array element
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 {}