for / while else doesn't make sense

Steven D'Aprano steve at
Sun Jun 12 22:12:09 EDT 2016

On Mon, 13 Jun 2016 04:44 am, Michael Selik wrote:

> On Sun, Jun 12, 2016 at 6:11 AM Steven D'Aprano <
> steve+comp.lang.python at> wrote:
>> - run the for block
>> - THEN unconditionally run the "else" block
> Saying "unconditionally" is a bit misleading here. As you say, it's
> conditioned on completing the loop without break/return/raise.

It's also conditional on the OS not killing the Python process, conditional
on the CPU not catching fire, conditional on the user not turning the power
of, and conditional on the sun not exploding and disintegrating the entire

In the absence of any event which interferes with the normal execution of
code by the Python VM, and in the absence of one of a very few
explicit "JUMP" statements which explicitly jump out of the compound
for...else statement, the else clause is unconditionally executed after the
for clause.

Happy now?


More information about the Python-list mailing list