Simple if-else question

dksr dksreddy at gmail.com
Wed Sep 30 11:42:13 CEST 2009


On Sep 29, 6:38 pm, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
> 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 when there are no
> > iterations.
>
> It will execute when there are no iterations. Did you mean to say people
> think it will execute *only* when there are no iterations?

Yes thats what I thought. for-else looks similar to if-else and in if-
else, else part is executed only when if part is not executed, but in
for-else it has entirely a different job.
Thats somewhat confusing, though it will be clear after playing around
with it.

- dksr



More information about the Python-list mailing list