[sf-perl] Opinions on: next LABEL;

Garth Winter Webb garth at perijove.com
Wed May 11 22:44:08 PDT 2005


On Wed, 2005-05-11 at 11:22, David Alban wrote:
> Greetings,
> Opinions sought.  Way back when, I learned that "goto" was a fourletter word in structured programming.  Since, I haven't needed to useit.
> I'm in a situation now where I'd like to:
>   FOO:  for ( ... ) {
>     for ( ... ) {
>        ...some condition... and next FOO;
>     } # for
>   } # for
> It seems more straight forward than using a setting state variable inthe inner loop, calling next without a label, and then examining thestate variable at the beginning of the outer loop.
> Anyone have any opinions, strong, style, or otherwise they'd like toshare about the appropriateness of using:
>   next LABEL;
> I know TMTOWTDI, but I'm interested in your opinions.

My opinion is that if you understood and believed the reasoning that
said 'goto' (and its Perl 'next LABEL' equivalent) was a bad thing you
should be consistent and find another way to do this.  Otherwise, why
bother avoiding it any other time?

As for another way, I think it depends heavily on what you are trying to
do.  However, if there is no code between the end of the inner loop and
the end of the outer loop, you could just use 'last' instead:

  for (...) {
    # Possibly code here
    for (...) {
      # some code here
      last if $blah;
    }
    # no code here
  }

Garth

> Thanks,David-- Live in a world of your own, but always welcome visitors._______________________________________________SanFrancisco-pm mailing listSanFrancisco-pm at pm.orghttp://mail.pm.org/mailman/listinfo/sanfrancisco-pm
-- 
Garth Winter Webb <garth at perijove.com>


More information about the SanFrancisco-pm mailing list