<p>Yeah it's definitely non trivial. Reading this is what got me thinking about it in Python: <a href="http://mortoray.com/2011/10/23/the-ideal-language-has-goto/">mortoray.com/2011/10/23/the-ideal-language-has-goto/</a></p>

<div class="gmail_quote">On Mar 9, 2012 1:07 PM, "David Townshend" <<a href="mailto:aquavitae69@gmail.com">aquavitae69@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p>The biggest problem is not the new syntax.  It's the new type of object that would be needed, Label, which lies in some magical place half way between a name and a keyword. What would be the result of the following code?</p>


<p>loops = []<br>
for i in range(4) as label:<br>
    print(type(label), dir(label))<br>
    loops.append(label)<br>
for label in loops as newlabel:<br>
    break label</p>
<p>David </p>
<div class="gmail_quote">On Mar 9, 2012 1:08 AM, "Westley Martínez" <<a href="mailto:anikom15@gmail.com" target="_blank">anikom15@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

On Fri, Mar 09, 2012 at 02:52:08AM +0800, Matt Joiner wrote:<br>
> Several languages allow break and continue statements to take a count<br>
> or loop label for greater flexibility.<br>
><br>
> Dealing with nested loops and control flow around them is definitely<br>
> something I and probably most programmers deal with everyday.<br>
> Generally for very complex control flow one might employ functions,<br>
> and use return statements to work around any shortcomings. This is not<br>
> always ideal in CPython because of the performance cost of function<br>
> calls, and lack of anonymous functions. The other work around is<br>
> usually goto statements, which clearly aren't available or appropriate<br>
> in Python.<br>
><br>
> So what about the following extensions?<br>
><br>
> Allow for and while statements to be labelled using "as".<br>
><br>
> Allow break and continue to take the name of a containing loop, or an<br>
> integer. The corresponding named loop, or the nth containing loop are<br>
> treated as though they are the nearest enclosing loop.<br>
><br>
> loop_label ::=  identifier<br>
><br>
> break_stmt ::=  "break" [decimalinteger | loop_label]<br>
><br>
> continue_stmt ::=  "continue" [decimalinteger | loop_label]<br>
><br>
> while_stmt ::=  "while" expression ["as" loop_label] ":" suite<br>
>                 ["else" ":" suite]<br>
><br>
> for_stmt ::=  "for" target_list "in" expression_list ["as" loop_label] ":" suite<br>
>               ["else" ":" suite]<br>
><br>
> Here's a really naive example:<br>
> for a in b as c:<br>
>     for d in e:<br>
>         break c # or break 2<br>
>     for f in g:<br>
>         continue c # or continue 2<br>
<br>
-1; if we do this we might as well add goto labels.<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</blockquote></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br></blockquote></div>