A downto iterator, which starts at a higher number and loops to a lower number. : downto « Statement « Ruby






A downto iterator, which starts at a higher number and loops to a lower number.


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

sum = 0

0.downto(0) do |loop_index|
  sum += grades[loop_index]
end

average = sum / grades.length

puts average

 








Related examples in the same category

1.Both the Integer and Date classes have downto methods
2.number of minutes you want to count down.
3.downto method with integer
4.downto with block