From: jamison edmonds Date: 2006-11-08T03:08:44+09:00 Subject: Re: 99 bottles of beer...pg57 --0-930684391-1162922921=:74580 Content-Type: text/plain; charset=iso-8859-7 Content-Transfer-Encoding: quoted-printable Thanks :-}=0A=0A----- Original Message ----=0AFrom: Sammy Larbi =0ATo: ruby-talk ML =0ASent: Tuesday, No= vember 7, 2006 11:57:01 AM=0ASubject: Re: 99 bottles of beer...pg57=0A=0AHi= Jamison,=0A=0AThe first thing I would do is remove the duplication with:= =0A=0Aputs '99, Bottles of beer on the wall, 99 bottles of beer,'=0Aputs 't= ake one down, pass it around,' =0A=0A=0Aand put that in the loop. Since yo= ur code in the loop does the same =0Athing, you could just decrement the va= lue of first after printing the =0Acurrent lyrics, and let that only reside= in 1 place instead of two. =0AThis way, if the song changes to something = like "take one down, take a =0Abig swig and pass it around," you only need = to change it in one place.=0A=0A=0A=0AAlso, it doesn't appear the "if first= !=3D 1" block will _never_ be =0Aexecuted (and I don't see a need for it e= ven if it was), so you could =0Aremove it and just decrement the value of f= irst. =0A=0AFinally, I think the variable name of first could be better nam= ed as to =0Awhat it represents. After the first bottle of beer is removed = from the =0Awall, it no longer represents the first bottle. So, I might go= with =0Asomething like current_bottle, or just anything that describes it = better =0Areally.=0A=0A-Sam=0A =0A=0A=0A=0Ajamison edmonds wrote, On 11/7/2= 006 11:37 AM:=0A> Hi =0A>=0A>=0A>=0A> I=A2m reading the book Learn to Progr= am, by Chris Pine. I=0A> wanted to see if my program 99 bottles of beer on = the wall, from (pg.57 or http://pine.fm/LearnToProgram/?Chapter=3D06 ) is= =0A> o.k.? =0A>=0A>=0A> An online search thru Google found Ruby-Talk, and = I=0A> instantly bookmarked it.=0A>=0A>=0A> Now I=A2m on the list.=0A>=0A>= =0A> Any thoughts would be appreciated ;) =0A>=0A>=0A> Hears my try at it= =0A>=0A>=0A> Thanks=0A>=0A>=0A> puts=0A> puts '99, Bottles of beer on the w= all, 99 bottles of beer,'=0A> puts 'take one down, pass it around,' =0A> fi= rst =3D 99=0A> while first !=3D 1 =0A> if first !=3D 1=0A> first = =3D first -1=0A> end=0A> puts first.to_s + ' Bottles of beer on the w= all, ' + first.to_s + ' bottles of beer,'=0A> puts 'take one down pass it= around,'=0A> end =0A> puts '0,Bottles of beer on the wall ;)' =0A>=0A>=0A= >=0A> =0A=0A=0A=0A=0A=0A=0A=0A=0A --0-930684391-1162922921=:74580--