GoTo considered missing

Chris Liechti cliechti at gmx.net
Tue Jul 2 21:48:21 EDT 2002


"Harvey Frey" <hsfrey at earthlink.net> wrote in
news:mailman.1025657644.14273.python-list at python.org: 

>     OK. I'm a spaghetti-coder from way back, new to Python.
> I didn't even realize there was no "goto" till I tried to rewrite a
> big C program in Python.
> 
>     Breaks and Continues are fine for single loops, but:
> What is the approved Python method for getting from the bottom of a
> set of nested loops to the top?

you can do that nicely with exceptions:

class AbortLoop(Exception): pass

try:
    	while 1:
    	    	for i in range(99):
    	    	    	if i == 57:
    	    	    	    	raise AbortLoop
except AbortLoop: pass

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list