Tim Golden <m...@timgolden.me.uk> writes: > On 17/12/2010 15:53, Steve Holden wrote: > > [... snip example of for-else ...] > >> This construct appears to be unpopular in actual use, and when it comes >> up in classes and seminars there is always interesting debate as people >> discuss potential uses and realise there are useful applications. > > I use this not infrequently, and I like it when it seems to be an > elegant way to express the code path. But I still misremember from > time to time and assume that the "else" clause fires when the for > loop is empty.
I use it from time to time, even though, like you, I used to always be unsure when the "else:" suite would be executed. I now remember this idiom as the "break else" construct: either the loop breaks, or the "else:" suite is executed. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list