http://www.perlmonks.org?node_id=136179


in reply to do/redo or for(;;): what's Kosher?

For infinite loops I like
while(1>0) { # do stuff }
This makes it really obvious that I mean 'forever'. Some of my co-workers have said that it really jumps out at them.

It should work perfectly the first time! - toma

Replies are listed 'Best First'.
Re: Re: do/redo or for(;;): what's Kosher?
by Anonymous Monk on Jan 04, 2002 at 12:35 UTC
    Personally, I just omit the condition all together:
    while() { ... }
    Not sure why it works, but it does.
      This is why it works:
      2;0 juerd@ouranos:~$ perl -MO=Deparse -e'while () { print "1\n" }' for (;;) { print "1\n"; } -e syntax OK


      Many people aren't going to like this:
      2;0 juerd@ouranos:~$ perl -MO=Deparse -e'while (1) { print "1\n" }' for (;;) { print "1\n"; } -e syntax OK


      2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

Re: Re: do/redo or for(;;): what's Kosher?
by robin (Chaplain) on Jan 04, 2002 at 19:39 UTC
    Along similar lines, I sometimes use
    until (2 + 2 == 5) { ... }
    which evokes eternity beautifully, in my mind.
      Reminds me of a friend of mine (Hendrix fan), who always uses
      
        if (6==9)
      
      as a break condition. Very cool, IMO.