On Wed, Feb 8, 2012 at 5:21 PM, Joel Goldstick <joel.goldst...@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
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor