Latest web development tutorials

Perl last statement

Perl cycle Perl cycle

Perl last statement is used to exit the loop statement block, thus ending the cycle, the statements are not executed last statement, continue statement block is no longer executed.

grammar

The syntax is as follows:

last [LABEL];

flow chart

Examples

#!/usr/bin/perl

$a = 10;
while( $a < 20 ){
   if( $a == 15)
   {
       # 退出循环
       $a = $a + 1;
       last;
   }
   print "a 的值为: $a\n";
   $a = $a + 1;
}

The above program, the output is:

a 的值为: 10
a 的值为: 11
a 的值为: 12
a 的值为: 13
a 的值为: 14

Perl cycle Perl cycle