PEP 315: Enhanced While Loop

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Sun May 4 21:06:37 EDT 2003


> From: rzed [mailto:rzantow at ntelos.net]
> 
> This does not strike me as "natural" in Python. By indenting the code
> block as shown, a Python programmer would naturally see two 
> blocks, the
> second conditioned by a while statement. The normal logic of a while
> would mark it as the loop beginning, not as somewhere in the 
> middle of a
> loop.

IMO, this is the crux of the argument.

    do:
        something
    while test:
        something else

looks like two separate things.

The traditional argument here is

    try:
        something
    except:
        something else

But there is a major difference. Once something enters the except: clause, it does not go back to the try: clause. The processing is one-way at the same indentation level.

OTOH, with do: while:, the processing loops back to across the indentation level.

The only way I could see the above being pythonic would be if it were of the form (ignoring existing meanings of such code):

    do:

        something

        while test:
            something else

>From there it's a short step to

    do:

        something

        if test:
            something else

to

    while True:

        something

        if test:
            something else

to (if desired)

    while True:

        something

        if not test:
            break

        something else

There are plenty of other arguments against the proposed syntactic structure (ambiguity, etc) but they've been well-argued.

I vote that the BDFL immediately reject this PEP so that we can put this issue to rest once and for all. That *is* why the PEP was created wasn't it ... to be rejected? ;)

Tim Delaney





More information about the Python-list mailing list