Skip to content

Instantly share code, notes, and snippets.

@agentfin
Created December 14, 2011 14:08
Show Gist options
  • Save agentfin/1476700 to your computer and use it in GitHub Desktop.
Save agentfin/1476700 to your computer and use it in GitHub Desktop.
Start from anywhere, 99bottles of beer song.
# 99 bottles of beer on the wall
# get a number of bottles
puts 'How many bottles do you have?'
bottles = gets.chomp.to_i
# set the loop to go til there are no more bottles
# we should be able to do this as an ".each do ||"
# but ruby has the hate today.
while bottles != 0
# get the song going
puts "#{bottles} bottles of beer on the wall."
puts "#{bottles} bottles of beer!"
puts 'Take one down, pass it around.'
puts "#{bottles - 1} bottles of beer on the wall!"
# can drop the subtraction in at then end of the loop section
# -= is nice shorthand that doesnt require brackets or anything
bottles -= 1
end
puts 'AND THEN WE ALL DRANK WHISKEY!!!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment