[Tutor] (no subject)
joel.goldstick at gmail.com
Thu Feb 9 00:25:15 CET 2012
On Wed, Feb 8, 2012 at 6:00 PM, Jerry Hill <malaclypse2 at gmail.com> wrote:
> On Wed, Feb 8, 2012 at 5:21 PM, Joel Goldstick <joel.goldstick at gmail.com>
>> 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.
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
oops.. sorry.. yes else runs if the loop completes without a break.. duh!
More information about the Tutor