On Aug 12, 2010, at 19:08, Kryten <[email protected]> wrote:
> Hi,
>
> Complete newbie.
>
> Is there any way to use "next" from within a foreach loop?
>
> All the examples I have seen/read use a while loop to demo.
Yes, next will work on for/foreach, while, and until loops. So you can say
for my $num (1 .. 10) {
next if $num % 2;
print "$num\n";
}
To print the even numbers between 1 and 10 (inclusive).
The next, last, and redo loop control statements will even work on bare blocks:
my $i = 0;
{
print "infinite loop: ", $i++;
sleep 1;
redo;
}
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/