Perl last Statement
The Perl last statement is used to exit a loop block, thereby terminating the loop. Statements following the last statement are not executed, nor are the statements within the continue block.
Syntax
The syntax 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 will output:
The value of a is: 10
The value of a is: 11
The value of a is: 12
The value of a is: 13
The value of a is: 14