#!/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.) |