Working around a lack of 'goto' in python

Y2KYZFR1 jarrodhroberson at yahoo.com
Tue Mar 9 17:36:02 CET 2004


Lou Pecora <pecora at anvil.nrl.navy.mil> wrote in message news:<pecora-B27EA8.11594308032004 at ra.nrl.navy.mil>...
> In article <c718a6cf.0403080841.6d35a548 at posting.google.com>,
>  jarrodhroberson at yahoo.com (Y2KYZFR1) wrote:
> 
> > "Brett" <abc at def.net> wrote in message 
> > news:<UBo2c.26879$pg4.12221 at newssvr24.news.prodigy.com>...
> > > Two areas where I've found 'goto' two be useful in other languages are in
> > > (untested examples in C++)
> > > 
> > > (1) deeply nested loops
> > > 
> > > for (k=0; k < 10; ++k)
> > > for (j=0; j < 10; ++j)
> > > for (i=0; i <10; ++i)
> > >     if (/* some test */) goto END;
> > > 
> > > END: /* continue */;
> > > 
> > > and (2) repeating a while or for loop from the beginning:
> > > 
> > > BEGIN:
> > > for (n=0; n < 20; ++n)
> > >     if (/* some test */) goto BEGIN;
> > > 
> > > What are the techniques in python for simulating these algorithms without a
> > > 'goto' command?
> > > 
> > > Thanks.
> > 
> > Step away from the computer slowly . . .
> > 
> > There is absolutely NO LEGITIMATE REASON to use GOTO in any modern
> > language, ESPECIALLY Python, EVER!
> > 
> > No stay away from computers until you understand how and why this is.
> 
> 
> Bull.  I've used goto's in similar cases as those presented.  I have 
> found that in the right cases they are quite readable.  Never had a 
> problem with them when used like this.
> 
> So you didn't answer the question, how would you do this clearly in 
> Python?
> 

same way you would do it in any other OBJECT ORIENTED language. Use
the appropriate pattern.



More information about the Python-list mailing list