How to break out of two nested for loops?

Chris Liechti cliechti at
Mon Jan 21 17:10:46 EST 2002

"Francois Petitjean" <littlejohn.75 at> wrote in
news:3c4c8a45$0$3191$626a54ce at 
>                     break   # break 2 ??
> A simple solution would be to have a nested function  interp_i  with
>   ret = self.match(line)
>   if ret: return ret

some day ago there was a discussion right about that....

however a simple solution is to raise an exception and catch it outside the 

class Stop(Exception): pass

    	for ...
    	    	for ...:
    	    	    	if  ...: raise Stop
except Stop:

you could also throw some existing Exception, but when you use you own 
youre sure that you don't accidently drain an error.


Chris <cliechti at>

More information about the Python-list mailing list