SPUG: Loop styles: goto vs. redo

Richard Anderson richard at richard-anderson.org
Tue Jul 2 20:27:45 CDT 2002


----- Original Message -----
From: "dancerboy" <dancerboy at strangelight.com>
To: <spug-list at pm.org>
Sent: Tuesday, July 02, 2002 10:50 AM
Subject: Re: SPUG: Re: Loop styles: goto vs. redo
> I personally dislike goto's and their ilk, so I consider these both
> somewhat hideous.  IMHO, a better alternative is:
>
>    my $done = 1;
>    do {
>        for  (....) {
>            unless(...) {
>                ...
>                $done = 0;
>            }
>        }
>    } while ( not $done );
>
That is either a once-only loop or an infinite loop - it's not equivalent to
the original code.

Good point about avoiding negatively-named variables like $not_done, which
can lead to confusing constructions like if(not $not_done) {}

Cheers,
Richard
richard at richard-anderson.org
www.richard-anderson.org
www.raycosoft.com





 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




More information about the spug-list mailing list