[Python-Dev] PEP 340: Breaking out.

Shane Hathaway shane at hathawaymix.org
Wed May 4 21:31:23 CEST 2005


Ka-Ping Yee wrote:
> On Wed, 4 May 2005, Shane Hathaway wrote:
>>
>>    for name in filenames:
>>        opening(name) as f:
>>            if f.read(2) == 0xFEB0:
>>                break for
> 
> 
> This is very elegant.

Thanks.

>  It works beautifully with "break", though at
> first that natural analogs "continue for", "continue while" appear to
> conflict with Guido's proposed extension to "continue".
> 
> But if we choose the keyword "with" to introduce an anonymous block,
> it comes out rather nicely:
> 
>     continue with 2
> 
> That's easier to read than "continue 2", in my opinion.  (If it's not
> too cute for you.)

Or perhaps:

    continue yield 2

This would create some symmetry, since generators will retrieve the
value passed by a continue statement using a yield expression.

Shane


More information about the Python-Dev mailing list