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.