[Python-Dev] PEP 340: Breaking out.

Paul Moore p.f.moore at gmail.com
Fri May 6 10:41:42 CEST 2005


On 5/6/05, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Seems to me it should be up to the block iterator whether
> a break statement gets caught or propagated, since it's
> up to the block iterator whether the construct behaves
> like a loop or not.
> 
> This could be achieved by having a separate exception
> for breaks, as originally proposed.
> 
> If the iterator propagates the Break exception back out,
> the block statement should break any enclosing loop.
> If the iterator wants to behave like a loop, it can
> catch the Break exception and raise StopIteration
> instead.

Yes, that's exactly what I was trying to say! I don't know if it's
achievable in practice, but the fact that it was in the original
proposal (something I'd forgotten, if indeed I ever realised) makes it
seem more likely to me.

Paul.


More information about the Python-Dev mailing list