for what are for/while else clauses

Fredrik Lundh fredrik at pythonware.com
Mon Nov 17 06:40:02 EST 2003


Alex Martelli wrote:

> > in every single case, it means "run once, if and only if the
> > controlling condition is false".
>
> I'm not sure what you mean by "the controlling condition" in this case.

the condition that controls if the conditional part of the statement
is executed.  from what I can tell, that's the usual definition.

> In a for/else or while/else construct, the only way to make your
> assertion true is to define "the controlling condition" as "a break
> [or return] interrupted the for or while loop [or an exception was
> propagated]" -- basically (quibbles on returns and exceptions apart)
> just what I said about "no break was executed".

for a while-statement, the controlling condition is the test at
the top.

for a for loop, the condition is "is there another item" (to quote the
language reference: "When the items are exhausted (which is imme-
diately when the sequence is empty) ... the loop terminates.".

for a try-except clause, the condition is "did the suite raise an
exception".

> the fact that the 'controlling condition' is "a break statement
> has executed"

that's not how it works.

</F>








More information about the Python-list mailing list