"do" as a keyword

Antoon Pardon apardon at forel.vub.ac.be
Wed Dec 12 08:07:33 EST 2007


On 2007-12-12, Terry Reedy <tjreedy at udel.edu> wrote:
>
> "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.

And this generic loop is faked. There is no notion in the language that
somehow connects this if statement to be a breaking condition for a
loop. If it would be a real syntatic construct in the language, it would
probably look more like:

do:
  pre_process
until condition:
  post_process

Personnaly I would have preferred to have this one generic loop
construct with no abbreviations instead of having the while abbreviation
that is to be combined with a break statement to fake the generic loop.

-- 
Antoon Pardon



More information about the Python-list mailing list