One line infinite for loop in Ruby?

Hi all,

How to write one line infinte for loop in Ruby?
I don't want loop{}.

Regards,
Anil Wadghule

···

--
Don't live to geek; geek to live.
http://anildigital.blogspot.com

How about:
while 1 do puts "OMG" end

hth,
-Harold

···

On 9/5/06, Anil Wadghule <anildigital@gmail.com> wrote:

Hi all,

How to write one line infinte for loop in Ruby?
I don't want loop{}.

Even better:

puts "OMG" while 1

···

On 9/5/06, Harold Hausman <hhausman@gmail.com> wrote:

On 9/5/06, Anil Wadghule <anildigital@gmail.com> 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

--
"What is your function in life?" - Killer

quoth the Harold Hausman:

> 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, Anil Wadghule <anildigital@gmail.com> wrote:

--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

nil while true

-austin

···

On 9/5/06, darren kirby <bulliver@badcomputer.org> wrote:

I have been wondering, is there a no-op in Ruby? Then you could do like in
Python:

while 1: pass

--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
               * austin@halostatue.ca * http://www.halostatue.ca/feed/
               * austin@zieglers.ca

quoth the Austin Ziegler:

> 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

···

On 9/5/06, darren kirby <bulliver@badcomputer.org> wrote:

--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

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

Austin Ziegler wrote:

···

On 9/5/06, darren kirby <bulliver@badcomputer.org> 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)

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Heres another one:

(a = lambda { a.call }).call

Of course this is one infinite loop that will probably terminate.

···

On Sep 5, 2006, at 11:26 PM, Devin Mullins wrote:

...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

>> 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?\

Yes! You can continue!

Devin

Regards,
Anil Wadghule

···

On 9/6/06, Devin Mullins <twifkak@comcast.net> wrote:
--
Don't live to geek; geek to live.
http://anildigital.blogspot.com

Anil Wadghule 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

···

On 9/6/06, Devin Mullins <twifkak@comcast.net> wrote:

Here's an ultimate one, just to make sure :slight_smile:

while 1
   nil while 1 && 1.times {redo} && raise rescue retry
end

Best,
Mike Dvorkin
http://www.rubywizards.com