On Wed, Feb 8, 2012 at 6:00 PM, Jerry Hill <[email protected]> wrote: > On Wed, Feb 8, 2012 at 5:21 PM, Joel Goldstick <[email protected]> > 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 - [email protected] > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > oops.. sorry.. yes else runs if the loop completes without a break.. duh!
-- Joel Goldstick _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
