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

Yuval Greenfield ubershmekel at gmail.com
Sat Jun 9 00:34:53 CEST 2012


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.


Yuval
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120609/4860da9d/attachment.html>


More information about the Python-ideas mailing list