<div dir="ltr"><div class="gmail_quote">On Thu, Oct 8, 2009 at 10:57 AM, Stefan Rank <span dir="ltr"><<a href="mailto:list-ener@strank.info">list-ener@strank.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
a suggestion/question related to the discussion about renaming for/else and while/else:<br>
Is it easy to generate a SyntaxWarning if you use these constructs without a break or return statement in the loop? AFAICS, any such usage would be either wrong or unnecessary. (right?)<br>
<br></blockquote><div><br></div><div>Your question is good and valid except that "return" has nothing to do with it.</div><div><br></div><div>In order to understand the "else" clause it's better that you think of it as an "if not break" after the loop. Any way you look at it "return" behaves as expected - skips the "else" AND skips all the code that follows (much like "raise" would have). "break" is the only way to skip the "else" clause whilst still executing the code that follows the for/while loop.</div>
<div><br></div><div>So the only way to the "else" clause is useful is when a "break" can skip it. If there is no "break", you might as well remove the "else" and deindent.</div><div>
<br></div><div>--yuv</div></div></div>