[Python-ideas] for/else statements considered harmful

Ethan Furman ethan at stoneleaf.us
Thu Jun 7 15:14:36 CEST 2012

Devin Jeanpierre wrote:
> On Thu, Jun 7, 2012 at 6:50 AM, Stephen J. Turnbull wrote:
>> The reason they make such mistakes is that there's a strong
>> association of "else" with "if-then-else", and for many people that
>> seems to be somewhere between totally useless and actively misleading.
> I know it's really bad form to shift goalposts, but I can't help but
> offer an alternative hypothesis: What if it isn't that else is
> confusing, but that use of else is rare? People have lots of silly
> beliefs about things they never use, or haven't used in a very long
> time.

I use the for/else and while/else constructs, and still get them wrong 
-- the association with if/else is very strong for me, and my usage 
pattern is more along the lines of "if this iterable was empty at the 

I appreciate the correlation with except/else, and the failed search 
idea -- those should help me keep these straight even before my tests 
fail.  ;)


More information about the Python-ideas mailing list