Working around a lack of 'goto' in python

Lou Pecora pecora at anvil.nrl.navy.mil
Mon Mar 8 17:59:43 CET 2004


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?

-- Lou Pecora
     My views are my own.
"The Blues got pregnant, and they called the baby Rock 'n Roll" 
    - Muddy Waters



More information about the Python-list mailing list