[Tutor] For - if - else loop; print selective output

Steven D'Aprano steve at pearwood.info
Thu Oct 25 01:37:28 CEST 2012

On 25/10/12 03:49, Alan Gauld wrote:

> I confess I'm not keen on the else part of a for loop and never
>use it, I think it leads to more confusion than anything. It
>doesn't do what most folks seem to expect, it should probably be
>called 'end' or something similar rather than 'else' IMHO.

I am keen on it and do use it, but I agree with the second sentence.
It took me the longest time to stop thinking of for...else as
meaning "run this block of code if the for loop didn't run at all".
It really is an astonishingly bad choice of keyword, but it is a
useful feature.


More information about the Tutor mailing list