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.’
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?
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
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
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.
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:
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.
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 http:// www.macdevcenter.com/.
On Apr 10, 2007, at 9:34 PM, James Edward G. II wrote:
Ruby → Execute and Update ‘# =>’ Markers.
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 http:// www.macdevcenter.com/.
James Edward G. II
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.