[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: 99 bottles of beer...pg57

Sammy Larbi

11/7/2006 5:57:00 PM

Hi Jamison,

The first thing I would do is remove the duplication with:

puts '99, Bottles of beer on the wall, 99 bottles of beer,'
puts 'take one down, pass it around,'


and put that in the loop. Since your code in the loop does the same
thing, you could just decrement the value of first after printing the
current lyrics, and let that only reside in 1 place instead of two.
This way, if the song changes to something like "take one down, take a
big swig and pass it around," you only need to change it in one place.



Also, it doesn't appear the "if first != 1" block will _never_ be
executed (and I don't see a need for it even if it was), so you could
remove it and just decrement the value of first.

Finally, I think the variable name of first could be better named as to
what it represents. After the first bottle of beer is removed from the
wall, it no longer represents the first bottle. So, I might go with
something like current_bottle, or just anything that describes it better
really.

-Sam




jamison edmonds wrote, On 11/7/2006 11:37 AM:
> Hi
>
>
>
> Icm reading the book Learn to Program, by Chris Pine. I
> wanted to see if my program 99 bottles of beer on the wall, from (pg.57 or http://pine.fm/LearnToProgram/?... ) is
> o.k.?
>
>
> An online search thru Google found Ruby-Talk, and I
> instantly bookmarked it.
>
>
> Now Icm on the list.
>
>
> Any thoughts would be appreciated ;)
>
>
> Hears my try at it
>
>
> Thanks
>
>
> puts
> puts '99, Bottles of beer on the wall, 99 bottles of beer,'
> puts 'take one down, pass it around,'
> first = 99
> while first != 1
> if first != 1
> first = first -1
> end
> puts first.to_s + ' Bottles of beer on the wall, ' + first.to_s + ' bottles of beer,'
> puts 'take one down pass it around,'
> end
> puts '0,Bottles of beer on the wall ;)'
>
>
>
>