Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: while ()

by ikegami (Patriarch)
on Jun 07, 2005 at 16:30 UTC ( [id://464373]=note: print w/replies, xml ) Need Help??


in reply to while ()

It might be related to for (;;) being interpreted as while (1). This parallel's C's behaviour for for (;;).

Replies are listed 'Best First'.
Re^2: while ()
by blazar (Canon) on Jun 07, 2005 at 16:38 UTC
    I think so too. However perlsyn suggest that it is C-style for which is really a while loop in disguise and not the other way round.

      If for is really a while in disguise, maybe they allowed while to have a empty condition to create a simple transformation from for to while.

      In other words, if

      for (a; b; c) { d }

      is translated into

      a; while (b) { d } continue { c }

      having the while accept an empty condition simplifies the translation.

      By the way, C doesn't allow an empty while condition:
      a.cpp:5: ANSI C++ forbids an empty condition for `while'

Re^2: while ()
by ambrus (Abbot) on Jun 08, 2005 at 14:59 UTC

    I agree. The phenomenon that for in perl is equivalent to while is best shown in that for(;<>;){ has the same magic as while(<>){.

    Also I note that until(){ is accepted too, and it seems to mean until(1){, that is, it's not executed at all.

    Of course, while() means while(1) only as a prefix while. A suffix while (); has an empty list in its condition as expected, so it doesn't execute at all, a suffix while; is an error, and the results for until is similar.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://464373]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found