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
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.'
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
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.'
block of code for loop should be contained by
{...}
for one-liners, or
do ... end
for multi-line blocks.
try:
beerno =99
while beerno > 0 do
puts "#{beerno} bottles of beer on the wall, take one down, pass it around,"
beerno = beerno - 1
puts "#{beerno} bottles of beer on the wall."
end
end
of course, there are many ways to build this same looping/iterating/enumerating structure!
some are more rubyistic than others.
···
On Apr 10, 2007, at 12:44 AM, Merrie 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
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.'
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
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.'
----- Original Message ----- From: "John Joyce" <dangerwillrobinsondanger@gmail.com>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Monday, April 09, 2007 12:18 PM
Subject: Re: Infinate Loop - Please Advise
You have no looping structure.
block of code for loop should be contained by
{...}
for one-liners, or
do ... end
for multi-line blocks.
try:
beerno =99
while beerno > 0 do
puts "#{beerno} bottles of beer on the wall, take one down, pass it around,"
beerno = beerno - 1
puts "#{beerno} bottles of beer on the wall."
end
end
of course, there are many ways to build this same looping/iterating/ enumerating structure!
some are more rubyistic than others.
On Apr 10, 2007, at 12:44 AM, Merrie 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
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.'
Sorry, here's a better working example. I wrote the others quickly in irb. The trouble with irb is that it isn't the most graceful environment for writing nested conditions or loops or elements. It's possible, but easy to make mistakes. Anyway, the white space in the conditionals and looping constructs is pretty important to Ruby.
beer = 99
beer.downto(1) do |cerveza|
puts "#{cerveza} bottles of beer on the wall,"
puts "#{cerveza} bottles of beer..."
puts "take one down pass it around..."
if cerveza > 1
puts "#{cerveza - 1} bottles of beer on the wall"
else
puts "no mas cerveza..."
end
end
beer = 99
beer.downto(0) do |b|
puts "#{b} bottles of beer."
puts "take one, drink it."
puts "#{b - 1} left."
end
but that needs an if statement to take care of the negative beer!
beer = 99
beer.downto(0) do |b|
puts "#{b} bottles of beer."
if b > 0 do
puts "take one, drink it."
puts "#{b - 1} left."
end
end
Of course it could be shorter still. but that's for you to toy with.
why wouldn't you just have beer.downto(1) and ditch the if statement?
I did, a few moments later. doing that stuff in irb isn't always as easy as doing it in TextMate (note to self).
I like irb because I can just ask objects questions. But irb needs more flexibility (the ability to step into and out of writing a block to check something else, that would be useful) Access to all the running stuff and ability to change it while running. Oh. self.assend_to_heaven
If you're unfamiliar, Smalltalk lives in an 'image' which offers the
flexibility you describe, with a full-GUI IDE environment -- you can
inspect and manipulate live objects and code as you develop, test and
debug.
I've actually considered building a similar environment for Ruby,
should I find the time and as wxRuby becomes more stable. As a matter
of fact, I believe I remember reading on here that FreeRIDE was
developed with that particular aim in mind.
On one hand it seems superfluous, since Smalltalk already has one, but
on the other it would be a great deal of fun to do so, and it seems
like a fit with the language given Ruby's Smalltalk heritage.
···
On Apr 9, 2:17 pm, John Joyce <dangerwillrobinsondan...@gmail.com> wrote:
- snip -
I did, a few moments later. doing that stuff in irb isn't always as
easy as doing it in TextMate (note to self).
I like irb because I can just ask objects questions. But irb needs
more flexibility (the ability to step into and out of writing a block
to check something else, that would be useful) Access to all the
running stuff and ability to change it while running. Oh.
self.assend_to_heaven
Yeah! A SmallTalk-like environment would be wonderful.
irb is already pretty cool.
But it always seems to be just short of what it could be.
I kinda wish TextMate had its own irb session ability, then it could be in color and have lots of cool tricks too.
But these are dreams and wishes, because I am not about to write anything like this myself. Not that clever.
···
On Apr 10, 2007, at 9:50 AM, Ash wrote:
On Apr 9, 2:17 pm, John Joyce <dangerwillrobinsondan...@gmail.com> > wrote:
- snip -
I did, a few moments later. doing that stuff in irb isn't always as
easy as doing it in TextMate (note to self).
I like irb because I can just ask objects questions. But irb needs
more flexibility (the ability to step into and out of writing a block
to check something else, that would be useful) Access to all the
running stuff and ability to change it while running. Oh.
self.assend_to_heaven
So basically, you want Smalltalk
If you're unfamiliar, Smalltalk lives in an 'image' which offers the
flexibility you describe, with a full-GUI IDE environment -- you can
inspect and manipulate live objects and code as you develop, test and
debug.
I've actually considered building a similar environment for Ruby,
should I find the time and as wxRuby becomes more stable. As a matter
of fact, I believe I remember reading on here that FreeRIDE was
developed with that particular aim in mind.
On one hand it seems superfluous, since Smalltalk already has one, but
on the other it would be a great deal of fun to do so, and it seems
like a fit with the language given Ruby's Smalltalk heritage.
I kinda wish TextMate had its own irb session ability, then it could be in color and have lots of cool tricks too.
Two things:
1. TextMate does ship with xmpfilter wrapped in a command, so it's already possible to evaluate statements and see the results, while keeping all the editing advantages of TextMate. See Bundles -> Ruby - > Execute and Update '# =>' Markers.
2. I wrote an article about how to build interactive environments inside of TextMate. The techniques used in it, could be used to make an "IRbMate." It should be published next week on Radar – O’Reilly.
look forward to seeing it.
Kinda waiting to see what happens with the next version of TextMate too. Needs better multilingual support. This is the only thing I can really really be disappointed about in TM. Quite ironic that the premier Ruby and Rails editor in the west will barf on Japanese input, and that it is such a wonderful example of a good Mac app yet doesn't have the language support so well provided by Cocoa...
now we're way OT
···
On Apr 10, 2007, at 9:34 PM, James Edward Gray II wrote:
On Apr 9, 2007, at 10:54 PM, John Joyce wrote:
I kinda wish TextMate had its own irb session ability, then it could be in color and have lots of cool tricks too.
Two things:
1. TextMate does ship with xmpfilter wrapped in a command, so it's already possible to evaluate statements and see the results, while keeping all the editing advantages of TextMate. See Bundles -> Ruby -> Execute and Update '# =>' Markers.
2. I wrote an article about how to build interactive environments inside of TextMate. The techniques used in it, could be used to make an "IRbMate." It should be published next week on Radar – O’Reilly.