PEP 315: Enhanced While Loop

rzed Dick.Zantow at lexisnexis.com
Mon May 5 15:54:58 EDT 2003


Andrew Koenig wrote:
> Evan> Andrew Koenig wrote:
>>> while:
>>> <setup code>
>>> and while <condition>:
>>> <loop body>
>
> Evan> Now, *this* is why we have PEPs!  Without them, everything
> old is new Evan> again, every few years.
>
> Evan> See Guido's reaction:
>
> Evan>
>
http://groups.google.com/groups?q=g:thl1134131894d&selm=199901042051.P
AA20739%40eric.cnri.reston.va.us
>
> Evan> See the implementation announcement:
>
> Evan>
>
http://groups.google.com/groups?q=g:thl3737064544d&selm=7hsv80%24g9j%2
41%40news.tamu.edu
>
> Evan> I can't for the life of me remember how it died, though.
>
> Evan> wow-it's-been-four-years-ly yrs,
>
> That's hilarious!  I had nothing at all to do with Python in 1999,
> which means that I came up with the same idea completely
> independently.
>
> And Guido liked it too!  What are we waiting for?  :-)

While I agree that this syntax is an improvement over the original PEP
version, it still would create a block structure different from any
other in Python.

Andrew says that this:

>         while <condition1>:
>             <code1>
>         and while <condition2>:
>             <code2>
>         and while <condition3>:
>             <code3>

would be equivalent to this:

>
>         while <condition1>:
>             <code1>
>             if not (<condition2>): break
>             <code2>
>             if not (<condition3>): break
>             <code3>
>
... which means that the first 'while' and the second do not mean the
same thing. That's less than "obvious" (ergo, less than "Pythonic"?).
If "while" does not imply a looping construct, why use the word?
How about:

while <condition1>:
    <code1>
and if <condition2>:
    <code2>
and if <condition3>:
    <code3>

Now the if tests do not imply loops within loops, and because they are
anded (in some vague way), the failure of any of them would break out
of the while loop.

I'd still prefer to see an indention of the entire while block,
though -- it seems more obvious:

while <condition1>:
    <code1>
    and if <condition2>:
        <code2>
    and if <condition3>:
        <code3>

... or maybe not.

--
rzed








More information about the Python-list mailing list