Named loops for breaking
Jean-Michel Pichavant
jeanmichel at sequans.com
Wed Mar 10 08:22:36 EST 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:
>
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/a696624c92b91181/5b7479fdc3362b83?lnk=gst&q=break+named+loop#5b7479fdc3362b83
>
> 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.
JM
More information about the Python-list
mailing list