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.
William (Bill) Froelich (Guest)
on 2006-03-31 10:39
(Received via mailing list)
How's this for a solution.  Note I tried to only use constructs covered
up to the point of the exercise in the book.

numBottles = 99
while numBottles > 2
	puts numBottles.to_s + " bottles of beer on the wall, " +
numBottles.to_s + " bottles of beer,"
	puts "take one down, pass it around, " + (numBottles-1).to_s + "
bottles of beer on the wall!"
	puts ""
	numBottles = numBottles - 1
end
puts numBottles.to_s + " bottles of beer on the wall, " +
numBottles.to_s + " bottles of beer,"
puts "take one down, pass it around, " + (numBottles-1).to_s + " bottle
of beer on the wall!"
puts "Yay!"


--Bill
JB (Guest)
on 2006-03-31 12:41
(Received via mailing list)
William (Bill) Froelich wrote:

> numBottles = numBottles - 1
> end
> puts numBottles.to_s + " bottles of beer on the wall, " +
> numBottles.to_s + " bottles of beer,"
> puts "take one down, pass it around, " + (numBottles-1).to_s + " bottle
> of beer on the wall!"
> puts "Yay!"
>
>
> --Bill

  Wow! It was so simple once I saw how it should/could be done! I'd (for
some
reason) completely forgot to do the '+ <whatever> +' thing in a 'puts'!
I'm
terrible at learning things, having severe ADHD, so if you don't tire of
helping me, I won't tire of still trying to learn programming.

  One question though about something that's got me still a little
confused.
Why the 'while numBottles > 2' ?

  Anyway, I really do appreciate the help Bill! Thank you very much!
This topic is locked and can not be replied to.