[Python-ideas] Control Flow - Never Executed Loop Body
Ethan Furman
ethan at stoneleaf.us
Tue Mar 22 15:34:01 EDT 2016
On 03/22/2016 11:49 AM, Terry Reedy wrote:
> On 3/21/2016 9:29 AM, Steven D'Aprano wrote:
>> On Sun, Mar 20, 2016 at 11:19:54PM -0400, Terry Reedy wrote:
>>> On 3/20/2016 9:32 PM, Steven D'Aprano wrote:
>>>
>>>> I understood from the keyword that "else" ran *if the for block
>>>> didn't*, i.e. when the loop iterator is empty.
>>>> A perfectly natural mistake to make,
>
>>> Why is the truth a mistake?
>>
>> It's not the truth.
>
> Yes it is. When the iterator is empty, possibly after many iterations,
> and the iterator is tested, the else clause runs.
>
> > The else block does *not* only run if the for block doesn't run.
>
> I have never, ever, claimed that. Initially empty and empty after all
> items have been processed are different.
This is the heart of the issue: *initially empty* and *empty after all
items are exhausted* are different, but for/else and while/else treat
them the same.
--
~Ethan~
More information about the Python-ideas
mailing list