Perl continue Statement
Perl continue block is usually executed before the conditional statement judgment again.
continue statements can be used in while and foreach loop.
grammar
while loop continue statement syntax is as follows:
while(condition){ statement(s); }continue{ statement(s); }
foreach loop continue statement syntax is as follows:
foreach $a (@listA){ statement(s); }continue{ statement(s); }
Examples
continue to use while loop statement:
#/usr/bin/perl $a = 0; while($a < 3){ print "a = $a\n"; }continue{ $a = $a + 1; }
The above program, the output is:
a = 0 a = 1 a = 2
continue to use the foreach loop statement:
#/usr/bin/perl @list = (1, 2, 3, 4, 5); foreach $a (@list){ print "a = $a\n"; }continue{ last if $a == 4; }
The above program, the output is:
a = 1 a = 2 a = 3 a = 4