<br><br><div class="gmail_quote">2009/10/2 Stephen J. Turnbull <span dir="ltr"><<a href="mailto:stephen@xemacs.org">stephen@xemacs.org</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Yuvgoog Greenle writes:<br>
<br>
 > 1. Not allowing a for loop that has no "break" to have an "else". Just like<br>
 > "else" isn't allowed when there isn't an "except" in the "try". There really<br>
 > is no excuse, justification or sense in a "for" loop that has no "break" yet<br>
 > has an "else".<br>
<br>
</div>+1.  File an RFE against PyLint for sure, and against Python too.<br>
That's a *great* idea!<br></blockquote><div><br>Nonsense - there are several other ways to break out of a loop. Raising an exception or returning for example.<br><br>Michael<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
Bikeshedding follows.<br>
<div class="im"><br>
 > Antti's experiment got me asking, you can try this as well. Ask a person who<br>
 > knows python the following questions:<br>
 > Question #1: Do you know what happens when an "else" appears after a "for"<br>
 > loop?<br>
 >     if they answer yes then say nevermind.<br>
<br>
</div>Er, no.  It's more important if what people "know" is wrong than if<br>
naive guesses are wrong.<br>
<div class="im"><br>
 >     otherwise: continue to question #2.<br>
 > Question #2: When would the code in the "else" block execute? If you don't<br>
 > know, it's ok to guess.<br>
<br>
</div>I would fire a programmer who gave an answer.<0.5 wink>  He might do<br>
the same in his own code or in a review of someone else's.<br>
<div class="im"><br>
 > 3. Renaming this construct for py4k wouldn't be too crazy if you use the<br>
 > existing reserved words "not" and "break". Look at this code and please note<br>
 > that it doesn't need any comments to make it readable (as opposed to Nick's<br>
 > example, no offence):<br>
<br>
</div>Nick's example is far more readable IMO.  No offense.  I can tell you<br>
why, too.  In his example, the "else" is immediately preceded by the<br>
"if ... break" suite.  Because "break" can only happen once in a loop,<br>
I read the else as the alternative to breaking out.  Sloppy, yes, but<br>
since this is the common idiom using for-else, it works for me. :-)<br>
<br>
OTOH, "break" is an imperative; "not break" looks like a prohibition<br>
to me, not the target of a branch.  You could use "for: ... if not<br>
break:" but that looks ugly to me, and worse requires several tokens<br>
of lookahead to disambiguate from an ordinary if block.<br>
<br>
I'll leave it up to GvR to decide whether for-else is "less Pythonic"<br>
than try-except-else.<br>
<div class="im"><br>
 > And I can even think of a few use cases for having just "break:". This block<br>
 > would execute only upon "break" occurring. That way you could have loops<br>
 > like this:<br>
 ><br>
 > for item in list_of_stuff:<br>
 >     if item.is_awesome():<br>
 >         break<br>
 > break:<br>
 >     celebrate(list_of_stuff)<br>
<br>
</div>You'd need multiple breaks for this to make sense.  Else:<br>
<div class="im"><br>
    for item in list_of_stuff:<br>
        if item.is_awesome():<br>
</div>            celebrate(list_of_stuff)<br>
            break<br>
<br>
Some people think that having multiple breaks is bad style.<br>
<div><div></div><div class="h5"><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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><br><br><br>