If you have a collection, such as an array or a range, you can also use the Ruby each iterator to create a loop.
grades = [88, 99, 73, 56, 87, 64] sum = 0 grades.each do |grade| sum += grade end average = sum / grades.length puts average