TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:12524] Perl loop question



One of the things people often miss in Perl is the ability to put "headers" on
your loops:

THEFINITELOOP: while($x != 100)  # Finite loop starts here
    {
     print "hello world\n";      # Spam someone's screen
     $x = 5;
     THEINFINITELOOP: while(1)           # Infinite loop starts here
                                                  {
                                                   $x++;
                                                   if ($x == 50)
                                                      {
                                                       last THEFINITELOOP;
                                                       }
                                                   elsif ($x == .5) # Maybe 
with the "new math..."
                                                      {
                                                      last THEINFINITELOOP;
                                                       }
                                                   }
    }

The last command normally only exists the innermost loop - but with labels, you
can get it to exit any loop that it is inside.

Just a useful tip.

Nick Reinking