SPUG: Loop styles: goto vs. redo

dleonard at dleonard.net dleonard at dleonard.net
Tue Jul 2 23:21:57 CDT 2002


Umm, the concept of using while() was the point, the code snippet was an
example of said point.  The execution of implementing it to your exact
problem was left as an exercise to the reader.  However, since that point
was obviously missed...

my $done = 0;
while (!$done) {
 $done = 1;
 for (...) {
  unless (...) {
   $done = 0;
  }
 }
}

-- 

<Douglas Leonard>
<dleonard at dleonard.net>

On Tue, 2 Jul 2002, Richard Anderson wrote:

> ----- Original Message -----
> From: <dleonard at dleonard.net>
> To: <spug-list at pm.org>
> Sent: Tuesday, July 02, 2002 2:37 PM
> Subject: Re: SPUG: Loop styles: goto vs. redo
> >
> > Personally I'm more of a fan of while().
> >
> > my $done = 0;
> > while (!$done) {
> >  for (...) {
> >   if (...) {
> >    $done = 1;
> >   }
> >  }
> > }
> >
>
> This repeats UNLESS the conditional evaluates true.  This is not equivalent
> to the original loop, which repeats IF the conditional evaluates true:
>
> START_TESTS:
>     my $not_done = 0;
>     for (...) {
>         unless (...) {
>             ...
>             $not_done = 1;
>         }
>     }
>     goto START_TESTS if $not_done
>


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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