Labels: Create an infinite loop to demonstrate how last will break out of multiple code blocks. : Last « Statement « Perl






Labels: Create an infinite loop to demonstrate how last will break out of multiple code blocks.

  


    #!/usr/local/bin/perl -w

    # Define the label name.
    EXIT:
    {
       for (;;)
       {
           my $x = 0;
          for (;;$x++)
          {
             print "$x, \n";
             last EXIT if $x >= 5;
          }
       }
    }
    print "Out of for loops.\n";

   
    
  








Related examples in the same category

1.Breaking Out
2.Exit a loop
3.Exits using the last statement.
4.Last with label
5.The last statement breaks out of a loop from within the loop block.
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