Perl continue Statement
The Perl continue block is usually executed before the condition statement is evaluated again.
The continue statement can be used in while and foreach loops.
Syntax
The syntax format of the continue statement in a while loop is as follows:
while(condition){
statement(s);
}continue{
statement(s);
}
The syntax format of the continue statement in a foreach loop is as follows:
foreach $a (@listA){
statement(s);
}continue{
statement(s);
}
Example
Using the continue statement in a while loop:
Example
#/usr/bin/perl
$a = 0;
while($a < 3){
print "a = $a\n";
}continue{
$a = $a + 1;
}
The output of the above program is:
a = 0 a = 1 a = 2
Using the continue statement in a foreach loop:
Example
#/usr/bin/perl
@list = (1, 2, 3, 4, 5);
foreach $a (@list){
print "a = $a\n";
}continue{
last if $a == 4;
}
The output of the above program is:
a = 1 a = 2 a = 3 a = 4Other Extensions
Perl Loops