Perl continue statement
The Perl continue block is usually executed before the conditional statement is judged again.
The continue statement can be used in the while and foreach loops.
Grammar
The syntax format of the continue statement in the while loop looks like this:
while(condition){ statement(s); }continue{ statement(s); }
The format of the continue statement in the foreach loop is as follows:
foreach $a (@listA){ statement(s); }continue{ statement(s); }
Instance
Use the continue statement in the while loop:
#/usr/bin/perl $a = 0; while($a < 3){ print "a = $a\n"; }continue{ $a = $a + 1; }
The above procedure is performed and the output is:
a = 0 a = 1 a = 2
Use the continue statement in the foreach loop:
#/usr/bin/perl @list = (1, 2, 3, 4, 5); foreach $a (@list){ print "a = $a\n"; }continue{ last if $a == 4; }
The above procedure is performed and the output is:
a = 1 a = 2 a = 3 a = 4