Perl last Function

Advertisements


Description

This is not a function. The last keyword is a loop-control statement that immediately causes the current iteration of a loop to become the last. No further statements are executed, and the loop ends. If LABEL is specified, then it drops out of the loop identified by LABEL instead of the currently enclosing loop.

Syntax

Following is the simple syntax for this function:

last LABEL

last

Return Value

This does not return any value.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl

$count = 0;

while( 1 ){
   $count = $count + 1;
   if( $count > 4 ){
       print "Going to exist out of the loop\n";
       last;
   }else{
       print "Count is $count\n";
   }
}
print "Out of the loop\n";

When above code is executed, it produced following result

Count is 1
Count is 2
Count is 3
Count is 4
Going to exist out of the loop
Out of the loop


Advertisements
Advertisements