[Python-Dev] PEP 340: Breaking out.

Skip Montanaro skip at pobox.com
Tue May 3 20:11:10 CEST 2005


>>>>> "Guido" == Guido van Rossum <gvanrossum at gmail.com> writes:

    Guido> [Skip Montanaro]
    >> Yeah, but "block synchronized(v1)" doesn't look like a loop.  I think
    >> this might be a common stumbling block for people using this
    >> construct.

    Guido> How many try/finally statements have you written inside a loop?
    Guido> In my experience this is extreeeemely rare. I found no
    Guido> occurrences in the standard library.

How'd we start talking about try/finally?  To the casual observer, this
looks like "break" should break out of the loop:

    while True:
        block synchronized(v1):
            ...
            if v1.field:
                break
        time.sleep(1)

The PEP says:

    Note that it is left in the middle whether a block-statement
    represents a loop or not; this is up to the iterator, but in the
    most common case BLOCK1 is executed exactly once.

That suggests to me it's still not clear if the block statement is actually
a looping statement.  If not, then "break" should almost certainly break out
of the while loop.

BTW, what did you mean by "left in the middle" mean?  I interpreted it as
"still undecided", but it's an idiom I've never seen.  Perhaps it should be
replaced by something more clear.

Skip


More information about the Python-Dev mailing list