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