Named loops for breaking

Jean-Michel Pichavant jeanmichel at
Wed Mar 10 14:22:36 CET 2010

Daniel Klein wrote:
> Hey,
> I did a little searching and couldn't really find much recent on this.
> The only thing I found was this:
> Basically I'm wondering if there are any plans to implemented named
> loops in Python, so I can tell a break command to break out of a
> specific loop in the case of nested loops. Currently I'm using boolean
> flag variables, but I find that very clumsy. I know this idea of
> breaking out of specific loops from javascript; I guess java does it
> too. It just seems a very Pythonian idea to me: clear, promotes code
> legibility, seems obvious.
Strange that I've rarely been in need of such feature. Continues & 
breaks are mess-prone, adding an 'outter block' break feature would just 
increase the messing potential of such controls.
Just my opinion though.

Still there's a control that is able to break outter scopes : return.
So embed your loop in a function and you'll be able to break whenever 
you want.


More information about the Python-list mailing list