in reply to while () vs. while (1)

And it is strange that the statement modifier has a different effect:
print "Here\n" while();
does not produce an infiinite loop, whereas:
while(){print "Here 2\n"}
does, which is a bit inconsistent.

Update: I just tried the following in Rakudo*:
# perl6 while () { say "Hello" }
and it did not give an infinite loop, it dropped straight through. That might be an effect of () being an empty list (false), so I tried
while {say "Hello 2"}
but that would not compile. The bare loop statement is specifically for infinite loops in p6 SFAIK, but
while 1 {say "Hello 2"}
also works as expected.

Replies are listed 'Best First'.
Re^2: while () vs. while (1)
by ikegami (Patriarch) on Jan 22, 2011 at 06:51 UTC

    You seem to have forgotten that statement modifiers don't use parens.

    # EXRP while EXPR; print "Here\n" while ();

    is the equivalent of

    # while (EXPR) { EXPR; } while ( () ) { print "Here\n" }

    Both behave identically.

      perl -e"warn foo, last while;" syntax error at -e line 1, near "while;"

      - tye