Perl continue statement


Release date:2023-10-17 Update date:2023-10-21 Editor:admin View counts:250

Label:

Perl continue statement

Perl continue blocks are usually executed before the conditional statement is judged again.

continue statement can be used in the while and foreach in a loop.

Grammar

while in circulation continue the syntax format of the statement isas follows:

while(condition){
   statement(s);
}continue{
   statement(s);
}

In foreach circulation , the continue syntax format of the statement is as follows:

foreach $a (@listA){
   statement(s);
}continue{
   statement(s);
}

Example

while use in a loop continue statement:

Example

#/usr/bin/perl$a=0;while($a<3){print"a =$a\\n";}continue{$a=$a+1;}

Execute the above program, and the output is as follows:

a = 0
a = 1
a = 2

foreach use in a loop continue statement:

Example

#/usr/bin/perl@list=(1,2,3,4,5);foreach$a(@list){print"a
=$a\\n";}continue{lastif$a==4;}

Execute the above program, and the output is as follows:

a = 1
a = 2
a = 3
a = 4

Powered by TorCMS (https://github.com/bukun/TorCMS).