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
Asked
Active
Viewed 63 times
-3

Nirav Bhatt
- 6,940
- 5
- 45
- 89

user3553965
- 13
- 3
3 Answers
2
Ruby doesn't work like that for reverse ranges.
You should use some other way of doing it.
For instance:
99.downto(1).each do |current_iteration_number|
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

Ruby Racer
- 5,690
- 1
- 26
- 43
2
Instead of:
for current_iteration_number in 99..1 do
you can do:
for current_iteration_number in 99.downto(1) do
0
You can do it like this too
a= 99..1
(a.first).downto(a.last).each do |current_iteration_number|
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

Pavan
- 33,316
- 7
- 50
- 76