"do" as a keyword
Terry Reedy
tjreedy at udel.edu
Tue Dec 11 23:11:54 EST 2007
"Steven D'Aprano" <steve at REMOVE-THIS-cybersource.com.au> wrote in message
news:13lts6gb9t2j350 at corp.supernews.com...
||
| 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.
I disagree. Nothing is being faked. The generic loop is
while True:
pre_process
if condition: break
post_process
If there is no pre_process, abbreviate the first two lines as 'while
condition:'. If there is no post_process, some would like another
abbreviation. Understanable. But the use cases seem relatively few. And
anyway, a competant programmer must understand the generic loop and a
fraction form, which I believe is at least as common as the no post_process
case.
Terry Jan Reedy
More information about the Python-list
mailing list