in reply to Test break, but still doing

just as an addendum to what danger was saying, i name all my loop blocks; for example:

WHILE_BLOCK_1: while (stuff) { more stuff; next WHILE_BLOCK_1; }

this way i can always be very clear on what my  next, redo and  last statement are doing their stuff on: ... it also helps to point out where my code could be failing because i might be thinking that my  next statement applies to the wrong thing...

this is especially helpful on long loops...

magnus

Replies are listed 'Best First'.
(tye)Re: Test break, but still doing
by tye (Sage) on Feb 22, 2001 at 00:05 UTC

    Personally, if I ever find myself wanting to label a loop block, I seriously look into refactoring.

    last, next, and redo, have a lot more in common with the hated goto then they do with structured programming.

    In some ways they are worse than goto because it takes more effort to find where they are transfering control to (you have to work your way out from nested blocks checking whether each is a loop or not and the editors I use can easily jump to "MyLabel:" but don't have a shortcut for even "jump to top of enclosing loop" (and then to the bottom in case the top is "do {" and we can't tell from that whether we are in a loop or not), much less "jump to top (or bottom) of enclosing Perl loop".

    I don't feel too guilty using last, next, and redo sparingly for fairly small loops (I've even experimented with out-denting such lines, but I'm not sure the effect works). I prefer to refactor into a subroutine so I can use return (or, for a complex loop I'll refactor parts into subroutines so that I'm left with a small loop that uses last, next, or redo).

            - tye (but my friends call me "Tye")