[Tutor] (no subject)

Jerry Hill malaclypse2 at gmail.com
Thu Feb 9 00:00:59 CET 2012


On Wed, Feb 8, 2012 at 5:21 PM, Joel Goldstick <joel.goldstick at gmail.com>wrote:

> The else clause runs if the loop breaks for some reason.  So you would
> use it only to do some processing if the loop completes completely.
>
>
No.  The else clause only runs if the loop does NOT break out early.  The
else clause only runs if the loop runs to completion without breaking.

For what it's worth, I loathe for/else loops, and will probably never use
them in my code.  They confuse me every time I see them, and I have to go
look up the behavior.  My brain always jumps to the conclusion that the
"else" clause should run when we do hit a break, which is the exact
opposite of how it actually works.  Maybe if they had been written into the
language as for/then loops I would remember it correctly.

Jerry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120208/a5e2bf10/attachment.html>


More information about the Tutor mailing list