[Python-ideas] for/else statements considered harmful

Westley Martínez anikom15 at gmail.com
Thu Jun 7 04:45:14 CEST 2012

On Wed, Jun 06, 2012 at 07:20:07PM -0400, Alice Bevan–McGregor wrote:
>    for x in range(20):
>        if x > 10: break
>    else:
>        pass # we had no values to iterate
>    finally:
>        pass # we naturally fell off the loop
-1 for me.  The idea that finally is executed only when we naturally
fall off the loop is weird.  finally suggests that it will always be
executed, like in a try/finally clause.  I think the naming of else is
weird but can be understood.  If a change is a must I believe else
should keep its semantic and simply be renamed except, but I am +0 on

All in all the use cases would be extremely rare if existant.  I've
never actually seen a for/else or while/else block.

More information about the Python-ideas mailing list