Exercises from Chapter 6

“99 Bottles of Beer on the Wall”

(Found here.)

Write a program that prints out the lyrics to that beloved classic, “99 Bottles of Beer on the Wall.”

How You Could Do It

1: num_at_start = 5 ​# change to 99 if you want
num_now = num_at_start
5: while​ num_now > 2
puts ​"​​#{​num_now​}​​ bottles of beer on the wall, "​ +
"​​#{​num_now​}​​ bottles of beer!"
num_now = num_now - 1
10:  puts ​"Take one down, pass it around, "​ +
"​​#{​num_now​}​​ bottles of beer on the wall!"
end
puts ​"2 bottles of beer on the wall, 2 bottles of beer!"
15: puts ​"Take one down, pass it around, 1 bottle of beer on the wall!"
puts ​"1 bottle of beer on the wall, 1 bottle of beer!"
puts ​"Take one down, ...

Get Learn to Program, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.