Search code examples
rubyfor-loopcontrol-flow

What is wrong with this ruby for loop?


for current_iteration_number in 99..1 do      
   puts "#{current_iteration_number} of beer on the wall. 
   #{current_iteration_number} of beer. Take one down, 
   pass it around #{current_iteration_number} of beer."    
end

Solution

  • Instead of:

    for current_iteration_number in 99..1 do
    

    you can do:

    for current_iteration_number in 99.downto(1) do