Simple if-else question

John Yeung gallium.arsenide at gmail.com
Wed Sep 30 07:29:10 CEST 2009


On Sep 29, 1:15 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
> Hmm, I wonder if Python should emit a warning if an else is
> used on a for block with no break inside.  I don't think the
> else can be invoked in any other way.  As a bonus it could
> catch some cases where people mistakenly use it thinking it
> will execute [only] when there are no iterations.

[Edit from Duncan Booth]

I would definitely be in favor of a warning.  Yes, people should read
the docs more carefully, and yes, it would cost a certain amount of
annoyance to implement this.  But I don't think it would get in
people's way if they do know how to use else, and I think it would cut
down on the number of questions from mystified beginners, some of whom
are much more aggressive than this particular OP about claiming that
Python is broken (when it's actually behaving as designed).

John



More information about the Python-list mailing list