PEP 315: Enhanced While Loop

Oren Tirosh oren-py-l at hishome.net
Mon May 5 10:25:09 EDT 2003


On Mon, May 05, 2003 at 12:52:17PM +0000, Andrew Koenig wrote:
> > Python is not broken. But if Python could not be improved we wouldn't
> > need PEPs at all.
> 
> Agreed.
> 
> > * "do" is unclear
> > * do-while in other languages doesn't have 2nd suite
> > * do-while-while ambiguity
> > * unseen "do" changes the meaning of seen "while"
> 
> On the other hand, I proposed essentially the same idea for C back in
> 1977.  Unfortunately, Dennis didn't think it was worth the effort :-)

But C does allow assignment inside expressions, three-way conditionals
and comma as "evaluate both, return right". Together they cover most of 
what people might want the "setup" part for.

But adding such features to Python expressions will be quite unpythonic.

> >      perform:
> >          <setup code>
> >      whilst <condition>:
> >          <loop body>
> 
> This is obviously intended to be tongue-in-cheek.  However, it does give
> me a thought about how to express this notion in a way that is much clearer
> and requires no new keywords:
> 
>         while:
>             <setup code>
>         and while <condition>:
>             <loop body>

Nice. No new keywords. Cannot be easily confused with a C do/while loop.
This probably improves BDFL acceptance factor from -10 to -7 or better!

;-)

   Oren





More information about the Python-list mailing list