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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dbfe42fc2f2b9e82578936523b19cd3c?d=identicon&s=25 William (Bill) Froelich (Guest)
on 2006-04-01 07: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

Or

While beer > 0

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

Keep it up!

--Bill
This topic is locked and can not be replied to.