[Python-ideas] Nudging beginners towards a more accurate mental model for loop else clauses

Arnaud Delobelle arnodel at gmail.com
Sat Jun 9 09:46:25 CEST 2012


Hi,

(sent from my phone)
On Jun 8, 2012 11:35 PM, "Yuval Greenfield" <ubershmekel at gmail.com> wrote:
>
> On Fri, Jun 8, 2012 at 12:04 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>
>> (context for python-ideas: my recently checked in changes to the
>> tutorial, that added the final paragraph to
>>
http://docs.python.org/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
)
>>
>
> If we're on that subject then I think this
>
> > Loop statements may have an else clause; it is executed when the loop
terminates through exhaustion of the list (with for) or when the condition
becomes false (with while), but not when the loop is terminated by a break
statement.
>
> Doesn't hit the "break" nail on the head fast and hard enough in my
opinion. I'd replace it with something like:
>
> > Loop statements may have an else clause; it is executed immediately
after the loop but is skipped if the loop was terminated by a break
statement.
>

Yes. This is why I've been suggesting for a while that we call these
constructs for/break/else and while/break/else.

As Terry says, this is not the whole truth but you'd have to have a warped
mind not to extrapolate the correct behaviour when there is a return or
raise in the loop body.

Arnaud
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120609/602e6a8b/attachment.html>


More information about the Python-ideas mailing list