Agree with Rob that the "else" keyword confusing in the context of a for loop. In my mind, "for each pebble in the bag, give it to Ben, or else ..." has no clear semantic meaning. What do you mean, "or else"?<div>


<br></div><div>In my mind, better words for what "else" currently does seem to be "afterwards", "atend", "ending", "thereafter", or "subsequently".</div><meta charset="utf-8"><div>


<br></div><div>- Andrey</div><div><br><div class="gmail_quote">On Wed, Oct 7, 2009 at 10:44 AM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Tue, Oct 6, 2009 at 9:06 PM, Bruce Leban <<a href="mailto:bruce@leapyear.org" target="_blank">bruce@leapyear.org</a>> wrote:<br>
> Here you go:<br>
> do_except = True<br>
> for i in SEQ:<br>
>   do_except = False<br>
>   A<br>
> else:<br>
>   if not do_except:<br>
>     C  # suite_if_loop_is_not_broken<br>
> if do_except:<br>
>   B  # suite_if_loop_body_is_not_executed<br>
<br>
</div>This doesn't keep the else semantics the same; currently in a for-loop<br>
over an empty list, the else clause is still executed, but not in your<br>
case, since do_except remains true. You may have meant this<br>
intentionally but it means that adding 'except: pass' would change the<br>
semantics of a for+else loop, which I find unexpected.<br>
<br>
I now understand that you want the except clause executed when there<br>
were zero iterations (your wording "not executed" didn't mean anything<br>
to me). Naming it 'except' is a really bad idea though because it<br>
makes people thing of exception handling.<br>
<br>
I can somewhat sympathize with this desire, but I think there are<br>
already plenty of ways to do this without adding new syntax. In<br>
general the addition of new syntax ought to be a truly rare event, and<br>
with the still pending transition to Python 3.x, doubly so.<br>
<div><div></div><div><br>
> --- Bruce<br>
><br>
><br>
> On Tue, Oct 6, 2009 at 8:53 PM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>> wrote:<br>
>><br>
>> On Tue, Oct 6, 2009 at 8:46 PM, Bruce Leban <<a href="mailto:bruce@leapyear.org" target="_blank">bruce@leapyear.org</a>> wrote:<br>
>> > Switching gears a bit, here's what I want:<br>
>> ><br>
>> > for_stmt ::= "for" target_list "in" expression_list ":" suite_loop_body<br>
>> > ["except" ":" suite_if_loop_body_is_not_executed] ["else" ":"<br>
>> > suite_if_loop_is_not_broken]<br>
>> ><br>
>> > The except and else appear in this order to make it clear that except<br>
>> > takes<br>
>> > precedence. If the loop body is not executed at all then both conditions<br>
>> > are<br>
>> > true but it obviously is only useful if except takes precedence.<br>
>> > Comments?<br>
>><br>
>> I'm sure it's obvious to you what the except clause should do, but it<br>
>> isn't to me. :-( Assuming you're not proposing we change the meaning<br>
>> of else in the absence of except, and that its meaning together with<br>
>> except is a logical extension of this, can you show how we should<br>
>> translate a for-loop with an except clause into current Python? Say,<br>
>> what would I be writing today to get the exact effect of your proposed<br>
>><br>
>> for i in SEQ:<br>
>>  A<br>
>> except:<br>
>>  B<br>
>> else:<br>
>>  C<br>
>><br>
>> ?<br>
>><br>
>> --<br>
>> --Guido van Rossum (home page: <a href="http://www.python.org/~guido/" target="_blank">http://www.python.org/~guido/</a>)<br>
><br>
><br>
<br>
<br>
<br>
</div></div>--<br>
<div>--Guido van Rossum (home page: <a href="http://www.python.org/~guido/" target="_blank">http://www.python.org/~guido/</a>)<br>
</div><div><div></div><div>_______________________________________________<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>
</div></div></blockquote></div><br></div>