Created
April 13, 2012 01:33
-
-
Save coryschires/2372674 to your computer and use it in GitHub Desktop.
99 bottles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ha. Was posting this to help a friend who's learning. How have you been? Let's hang out.