in reply to Re^3: Re Execute Lines of Code ("loops")
in thread Re Execute Lines of Code

Now consider a bare block with both redo and last. It is exactly like two labels with gotos except that it is often less clear.

Then why not use loop labels for redo, next and last?

FILE: while ( my $file = $DIR> ) { ... last FILE if ( condition1 ); ... redo FILE if ( condition2 ); }

Replies are listed 'Best First'.
Re^5: Re Execute Lines of Code (labels)
by tye (Sage) on Jan 28, 2008 at 06:20 UTC

    After thinking about that for a while, I'm coming to like the idea. It clues in the reader that some unusual flow is going to happen with this loop so they can't assume the loop conditional is the end of the story. And it makes the unusual, mid-loop flow changes easier to spot.

    I still prefer to just avoid such. But next time I find the desire to use one, I'll consider that option.

    - tye        

      Other advantages are that it doesn't break when

      LOOP: while(1) { last LOOP; }
      becomes
      LOOP: while(1) { while ( condition ) { last LOOP; } }
      and does the right thing in
      THING: for my $thing (@things) { redo THING; }