On Aug 12, 2010, at 19:08, Kryten <kryte...@googlemail.com> 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: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to