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

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.)

Replies are listed 'Best First'.
Re5: while
by Hofmator (Curate) on Jul 16, 2001 at 17:50 UTC

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

    -- Hofmator