in reply to Re: Re: while
in thread while without parentheses

You're right of course, but then the while is a modifier to a simple statement. Modifiers are slightly different creatures, for instance you can't use loop control operators or labels with modifiers.

Replies are listed 'Best First'.
Re: Re: Re: Re: while
by chipmunk (Parson) on Jul 16, 2001 at 02:56 UTC
    Here's a curiosity:
    #!/usr/local/bin/perl -w use strict; $_ & 1 ? next : print "$_\n" for 1 .. 10; my $i = 0; $i & 1 ? next : print "$i\n" while ++$i <= 10; __END__ 2 4 6 8 10 Can't "next" outside a block at loops.pl line 8.
    So you can use the loop control operators with the foreach statement modifier, but not with the while statement modifier. I know that these two features were not added to Perl at the same time (perl5.004 for the while statement modifier; perl5.005 for the foreach statement modifier). Perhaps this inconsistent behavior was an oversight.

    (I don't have access to perl5.6 right now, to see if it's the same way.)

      Same result with perl5.6.1 (ActiveState build 626).

      -- Hofmator