wood burning stoves*
The moose likes Other Languages and the fly likes Ruby: Range conditionals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Ruby: Range conditionals" Watch "Ruby: Range conditionals" New topic
Author

Ruby: Range conditionals

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The pragmatic guys book has this example. The input file is

input file

output:

But the output I get is all six lines.

Any thoughts on what's not working?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
The Pickaxe, second edition, page 68, under heading 'Ranges as Conditions', specific to version 1.8:


In older versions of Ruby, bare ranges could be used as conditions in if, while, and similar statements. You could, for example, have written the previous code fragment as:

This is no longer supported. Unfortunately, no error is raised; the test will simply succeed each time.


So what you do is:


Guy
[ November 15, 2006: Message edited by: Guy Allard ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Thanks! My book and software are not on the same versions.
 
 
subject: Ruby: Range conditionals
 
Similar Threads
Multiplication Table
Printing Int Array to File using PrintWriter
Program keeps locking up, not sure why
convert char to int in a string?
Southern Comfort on the rocks