Skip to content

Instantly share code, notes, and snippets.

@coryschires
Created April 13, 2012 01:33
Show Gist options
  • Select an option

  • Save coryschires/2372674 to your computer and use it in GitHub Desktop.

Select an option

Save coryschires/2372674 to your computer and use it in GitHub Desktop.
99 bottles
# Iterative solution
#
bottles = (0..99).to_a
bottles.reverse.each do |bottle|
if bottle.zero?
puts "#{bottle} bottles of beer on the wall. No more beer"
else
puts "#{bottle} bottles of beer on the wall.."
end
end
# Looping solution
#
bottles = 99
until bottles.zero? # you could also write: while bottles != 0
puts "#{bottles} bottles of beer on the wall.."
bottles = bottles - 1 # you could also use a shorthand: bottles -= 1
end
puts "#{bottles} bottles of beer on the wall. No more beer"
@tjbladez
Copy link

Totally. Let me know when

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment