"do" as a keyword

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Tue Dec 11 15:19:28 EST 2007


On Tue, 11 Dec 2007 15:06:31 +0000, Neil Cerutti wrote:

> When I use languages that supply do-while or do-until looping constructs
> I rarely need them.
...
> However, did you have an specific need for a do-while construct? Perhaps
> we could show you the alternatives.

"Need" is a strong word. After all, all looping constructs could be done 
with a conditional jump, so arguably we don't "need" while or for either.

But loops that run at least once is a basic element of algorithms. 
Perhaps not as common as the zero or more times of the while loop, but 
still fundamental. It is a shame it has to be faked using:

while True: # force the first iteration to always run
    process
    if condition: break

Ugly and misleading. But here to stay until Guido has an epiphany and 
decides that a do...until loop is elegant enough that it is well worth 
the addition of two new keywords. (I find the idea of do...while 
unspeakable. The test is backwards.)

Oh well... when I'm Malevolent Dictator For Life, Guido will do as he's 
told, and no mistake!!!

*wink*.



-- 
Steven.



More information about the Python-list mailing list