Forum: Ruby Re: Learn to Program, by Chris Pine

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
William (Bill) Froelich (Guest)
on 2006-04-01 09:17
(Received via mailing list)
First off, thanks to Dave for providing the explanation that should have
been in place of just my solution.

I also recommend putting the "beer = beer - 1" at the end of the loop
but that won't immediately allow you to remove the if unless you also
look at changing the loop criteria or provide a special check to handle
the last time through the loop.  Assuming you want to end with 0 bottles
of beer on the wall, then your last iteration through the loop will need
to be when beer = 1 which means you should also look to change your
while criteria.  Either of the following would work:

While beer >= 1


While beer > 0

Both of these will allow you to remove the extra if check.

Keep it up!

This topic is locked and can not be replied to.