Hi all,
How to write one line infinte for loop in Ruby?
I don’t want loop{}.
Regards,
Anil W.
Hi all,
How to write one line infinte for loop in Ruby?
I don’t want loop{}.
Regards,
Anil W.
On 9/5/06, Anil W. [email protected] wrote:
Hi all,
How to write one line infinte for loop in Ruby?
I don’t want loop{}.
How about:
while 1 do puts “OMG” end
hth,
-Harold
On 9/5/06, Harold H. [email protected] wrote:
On 9/5/06, Anil W. [email protected] wrote:
Hi all,
How to write one line infinte for loop in Ruby?
I don’t want loop{}.How about:
while 1 do puts “OMG” end
Even better:
puts “OMG” while 1
quoth the Harold H.:
On 9/5/06, Anil W. [email protected] wrote:
Hi all,
How to write one line infinte for loop in Ruby?
I don’t want loop{}.How about:
while 1 do puts “OMG” end
I have been wondering, is there a no-op in Ruby? Then you could do like
in
Python:
while 1: pass
hth,
-Harold
-d
On 9/5/06, darren kirby [email protected] wrote:
I have been wondering, is there a no-op in Ruby? Then you could do like in
Python:while 1: pass
nil while true
-austin
quoth the Austin Z.:
On 9/5/06, darren kirby [email protected] wrote:
I have been wondering, is there a no-op in Ruby? Then you could do like
in Python:while 1: pass
nil while true
Cool, thanks.
I’ve just realized you don’t even need the ‘nil’ to flesh out some
syntactically valid functions/methods/case statements that do nothing:
irb(main):005:0> def foobar
irb(main):006:1> end
=> nil
irb(main):010:0> x = 1
irb(main):011:0> if x == 2
irb(main):012:1> puts “Two!”
irb(main):013:1> elsif x == 1 # do nothing
irb(main):014:1> else
irb(main):015:1* puts “Not 1 or 2”
irb(main):016:1> end
=> nil
technically they return nil but that is incidental…
-austin
-d
I have been wondering, is there a no-op in Ruby? Then you could do
while 1: pass
nil while true
while true; end
…wait. Why are we doing this? And why are we disallowed from using
loop{}? Okay, here’s another:
alias repeat loop; repeat{}
Or:
(1…1.0/0)…each{}
How about:
callcc{|$cc|};$cc[]
Shall I continue, Anil?
Devin
On Sep 5, 2006, at 11:26 PM, Devin M. wrote:
Devin
Heres another one:
(a = lambda { a.call }).call
Of course this is one infinite loop that will probably terminate.
On 9/6/06, Devin M. [email protected] wrote:
(1…1.0/0)…each{}
How about:
callcc{|$cc|};$cc[]Shall I continue, Anil?\
Yes! You can continue!
Devin
Regards,
Anil W.
Austin Z. wrote:
On 9/5/06, darren kirby [email protected] wrote:
I have been wondering, is there a no-op in Ruby? Then you could do
like in
Python:while 1: pass
nil while true
Golfing slightly and not very interestingly:
0while 0
(that’s not a syntax error, oddly)
Anil W. wrote:
On 9/6/06, Devin M. [email protected] wrote:
Shall I continue, Anil?
Yes! You can continue!
Err… okay, I can think of another:
raise rescue retry
Wow… that one’s pretty elegant. This one much less so:
1.times { redo }
I’m out… maybe something cute with threads, or throw/catch, or ensure?
Is there a reason for your question? Just a ruby-talk game?
Devin
Here’s an ultimate one, just to make sure
while 1
nil while 1 && 1.times {redo} && raise rescue retry
end
Best,
Mike D.
http://www.rubywizards.com
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs