PEP 315: Enhanced While Loop
Andrew Koenig
ark at research.att.com
Mon May 5 11:11:26 EDT 2003
>> 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 :-)
Oren> But C does allow assignment inside expressions, three-way conditionals
Oren> and comma as "evaluate both, return right". Together they cover most of
Oren> what people might want the "setup" part for.
Yes.
Oren> But adding such features to Python expressions will be quite unpythonic.
Let's not talk about PEP308, OK?
>> while:
>> <setup code>
>> and while <condition>:
>> <loop body>
Oren> Nice. No new keywords. Cannot be easily confused with a C do/while loop.
Oren> This probably improves BDFL acceptance factor from -10 to -7 or better!
That's my guess too.
I must confess that I find this issue less important now that we have
generators. Before that, I was looking for a clean way of writing
while True:
line = infile.read()
if not line:
break
<process a line>
but with generators it is possible to write
for line in infile:
<process a line>
(Yes, I know that you don't need generators to allow such usages for
built-in types, but generators make it much easier to do similar things
with user-defined types)
More information about the Python-list
mailing list