[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Infinate Loop - Please Advise

SonOfLilit

4/9/2007 3:56:00 PM

You never decrement beerno.

On 4/9/07, Merrie <merries@comcast.net> wrote:
> This program produces an infinate loop. I am learning from Learn to Program and do not have a clear example how to do this particular example. It is suppose to count down the bottles and repeat the phrase until it reach 0 bottles of beer then end :)
>
> Merrie
> -------------------------------------------------------------------------------------
>
> beers = 99
> beerno = beers - 1.to_i
> while beerno != 1
> puts '99 bottles of beer on the wall, take one down, pass it
> around, there are ' + beerno.to_s + 'bottles of beer on the wall.'
>
> end

1 Answer

Phillip Gawlowski

4/9/2007 4:06:00 PM

0

SonOfLilit wrote:

> On 4/9/07, Merrie <merries@comcast.net> wrote:
>> This program produces an infinate loop. I am learning from Learn to
>> Program and do not have a clear example how to do this particular
>> example. It is suppose to count down the bottles and repeat the phrase
>> until it reach 0 bottles of beer then end :)
>>
>> Merrie
>> -------------------------------------------------------------------------------------
>>
>>
>> beers = 99
>> beerno = beers - 1.to_i
>> while beerno != 1
>> puts '99 bottles of beer on the wall, take one down, pass it
>> around, there are ' + beerno.to_s + 'bottles of beer on the wall.'
>>
>> end
>
> You never decrement beerno.

At least not within the while loop.

A: Because it makes it hard to read replies.
Q: Why is top-posting bad?

--
Phillip "CynicalRyan" Gawlowski
http://cynicalryan....

Rule of Open-Source Programming #33:

Don't waste time on writing test cases and test scripts - your users are
your best testers.