Perl last statement

Perl 循环Perl loops

The Perl last statement is used to exit the loop statement block, thereby ending the loop. Statements after the last statement are no longer executed, and the continue statement block is also no longer executed.

Syntax

The syntax format is as follows:

last [LABEL];

Flowchart

Example

#!/usr/bin/perl $a = 10; while( $a < 20 ){ if( $a == 15) { # Exit the loop $a = $a + 1; last; } print "The value of a is:$a\n"; $a = $a + 1; }

Executing the above program produces the following result:

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

Perl 循环Perl loops

Other extensions