<br><br><div class="gmail_quote">On Thu, Oct 1, 2009 at 8:11 PM, Yuvgoog Greenle <span dir="ltr"><<a href="mailto:ubershmekel@gmail.com">ubershmekel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div dir="ltr"><br><div>Question #2: When would the code in the "else" block execute? If you don't know, it's ok to guess.</div>
<div>    If they answer "when a break didn't occur", I'm willing to give you, the asker, up to 100 lines of patch code in whatever python project you want..</div><div>    If they answer "maybe when the for loop didn't run or was an empty list" then you don't owe me anything.</div>


<div><br></div></div></blockquote><div><br></div><div>When I see for/else I think of the second case even though I know it's not that. I think that second pattern is very common. In fact, I wrote code today that used it and I had to store the list in a variable and wrap the for in an if to test whether it was empty. Arguably, either one of these is appropriate for the word "else".</div>

<div><br></div><div>I'd rather something like:</div><div><br></div><div>    for x in y:</div><div>      stuff</div><div>    else if no_break:</div><div>      more stuff</div><div>    else if no_elements:</div><div>      more stuff</div>

<div><br></div><div>OK. This is ugly, but it's clear which of these is which use case. Surely someone can make this better in time for Python 4.</div><div><br></div><div>--- Bruce</div></div>