[Python-Dev] PEP 340: Breaking out.

Ronald Oussoren ronaldoussoren at mac.com
Thu May 5 13:13:58 CEST 2005


On 5-mei-2005, at 12:55, Nick Coghlan wrote:

> Alex Martelli wrote:
>
>> Looking for a file with a certain magicnumber in its 1st two  
>> bytes...?
>>
>> for name in filenames:
>>      opening(name) as f:
>>          if f.read(2) == 0xFEB0: break
>>
>> This does seem to make real-life sense to me...
>>
>
> Also consider the vast semantic differences between:
>
>    locking(lock):
>        for item in items:
>            if can_handle(item): break
>
>    for item in items:
>        locking(lock):
>            if can_handle(item): break
>
>
> Instead of simply acquiring and releasing the lock on each  
> iteration as one
> might expect, moving to the latter version *also* causes every item  
> to be
> checked, instead of only items up to the first one that can be  
> handled. The
> break magically becomes meaningless. How does this even come close  
> to executable
> pseudocode?

What's bothering me about the proposed semantics is that block  
statement behaves
like a loop while most use cases do no looping whatsoever.  
Furthermore the it doesn't
feel like loop either. In all three examples on this page I'd assume  
that the break
would break out of the for loop.

Ronald


More information about the Python-Dev mailing list