add the even numbers from 4 to 12 : step « Statement « Ruby






add the even numbers from 4 to 12


puts "What's the answer?"

sum = 0

4.step(12, 2) do |even_value|
  sum += even_value
end

puts "The answer is " + sum.to_s

 








Related examples in the same category