The last statement breaks out of a loop from within the loop block. : Last « Statement « Perl






The last statement breaks out of a loop from within the loop block.

  


$n=0;
while( $n < 10 ){
   print $n;
   if ($n == 3){
       last;  # Break out of loop
   }
   $n++;
}
print "Out of the loop.<br>";

   
    
  








Related examples in the same category

1.Breaking Out
2.Exit a loop
3.Exits using the last statement.
4.Labels: Create an infinite loop to demonstrate how last will break out of multiple code blocks.
5.Last with label
6.Use a label
7.Using a label.
8.Using the last statement in a foreach structure.
9.last if
10.last statement
11.last statement inside an if statement