PEP-315 ("do" loop)

Wayne Folta wfolta at netmail.to
Thu Feb 19 15:36:02 EST 2004


> Amen to that! I think this is only a matter of education. People
> should be told that 'while 1' construct is a good, simple, pythonic

That syntax is saying, "This is an infinite loop"... "well, wait a 
minute"... "there's some stuff down lower: the 'if ... break', which is 
the actual loop test"...

The loop condition is pathological. This idiom turns the instinctive 
meaning/use of 'while' on its head, and uses 'break' in the reverse of 
its usual role. It works, but its a programmer hack, an expedient 
measure, which is more the domain of perl than python.

Some people don't like my suggestion of 'until' because they assume it 
must mean 'while not'. But I don't think that's necessarily so. After 
all, the literal, spoken word meaning of "while X", could imply that 
the loop exits at any point where X becomes false. (As if there were an 
"if not X: break" after every line in the loop.) But as programmers, 
we've restricted it to mean that a test is done once at the top of the 
loop each time through.

Similarly, 'until' can have a narrower meaning.

By contrast, the "while True" construct is a kludge that works, not 
much different from creating loops with "if ... goto" because you don't 
have a "while".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2363 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040219/d3a21ea0/attachment.bin>


More information about the Python-list mailing list