Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Comparison question
Peter Vanderhaden
10/16/2007 12:46:00 AM
I'm looking at the Comparable module in a book, and I can't figure out
how to do a simple comparison. What I want to do is a loop based on a
counter. If the counter is less than 3, I want to execute the loop,
otherwise I want the loop to end. I'm used to coding something like if
$cnt < 3 but in Ruby that doesn't seem to work. Obviously I'm new to OO
programming, so can someone give me a simple example of how to do this,
or point me to a simple tutorial on how to do comparisons?
Thanks
--
Posted via
http://www.ruby-...
.
3 Answers
Peter Vanderhaden
10/16/2007 12:54:00 AM
0
Never mind, I figured it out, sorry!
Peter Vanderhaden wrote:
> I'm looking at the Comparable module in a book, and I can't figure out
> how to do a simple comparison. What I want to do is a loop based on a
> counter. If the counter is less than 3, I want to execute the loop,
> otherwise I want the loop to end. I'm used to coding something like if
> $cnt < 3 but in Ruby that doesn't seem to work. Obviously I'm new to OO
> programming, so can someone give me a simple example of how to do this,
> or point me to a simple tutorial on how to do comparisons?
> Thanks
--
Posted via
http://www.ruby-...
.
7stud --
10/16/2007 3:56:00 AM
0
Peter Vanderhaden wrote:
> Never mind, I figured it out, sorry!
>
Here are some ways you might not have thought of:
a)
arr = ["hello", "world", "goodbye", "mars"]
arr.each_with_index do |elmt, i|
if i == 3
break
end
puts elmt
end
--output:--
hello
world
goodbye
b)
(0..2).each {|i| print i}
--output:--
012
c)
3.times {|i| puts i}
--output:--
0
1
2
--
Posted via
http://www.ruby-...
.
Robert Klemme
10/16/2007 9:37:00 AM
0
2007/10/16, Peter Vanderhaden <bostonantifan@yahoo.com>:
> I'm looking at the Comparable module in a book, and I can't figure out
> how to do a simple comparison. What I want to do is a loop based on a
> counter. If the counter is less than 3, I want to execute the loop,
> otherwise I want the loop to end. I'm used to coding something like if
> $cnt < 3 but in Ruby that doesn't seem to work. Obviously I'm new to OO
> programming, so can someone give me a simple example of how to do this,
> or point me to a simple tutorial on how to do comparisons?
http://www.google.com/search?q=rub...
http://www.rub...
robert
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Comparison question
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password