[Python-ideas] Control Flow - Never Executed Loop Body

Ethan Furman ethan at stoneleaf.us
Thu Mar 24 14:28:00 EDT 2016


On 03/23/2016 03:25 PM, Terry Reedy wrote:
> On 3/22/2016 3:34 PM, Ethan Furman wrote:

>> This is the heart of the issue: *initially empty* and *empty after all
>> items are exhausted* are different,
>
> from the perspective of a particular loop.

 From the perspective of many, many (most?) people.  I use for loops and 
while loops *alot*, and I can count the times I have wanted to use the 
`else` clause in the meaning of "all my tests failed, so do this block" 
on the fingers of one hand.

>> but for/else and while/else treat them the same.
>
> Which is to say, each test is a test of current state, independent of
> history.

By the way, I appreciate your explanations -- they help make a little 
more sense out of it -- but the behaviour of `for/else` and `while/else` 
is definitely a learned exception to the general rule of "truthy -> this 
thing is something" / "falsey -> there is nothing here".

--
~Ethan~



More information about the Python-ideas mailing list