do...until wisdom found...

Bob Cannard bob_cannard at mentor.com
Tue Apr 17 12:28:15 EDT 2001


Dale Strickland-Clark wrote:
> How about, for "execute at least once":
> 
> REPEAT:
>         code
>         WHILE condition
> 
> REPEAT:
>         code
>         UNTIL condition

Has no one else found that the majority of while-type
loops actually need some code before the test and some
after? Doubly so in Python where it seems impossible
to embed a local side effect in the while condition.
As a result, most non-for loops degenerate into

        while 1:
            set up for this cycle
            if c: break
            whatever needs to be done

Instead we keep getting suggestions for another loop
structure that's comparable in lack of generality to
"while", instead of taking a good look at how loops
are formed in practice and generalizing the concept
accordingly. If new syntax were to be added to the
language, I'd rather see something like Dale's
suggestion but removing the constraint that the UNTIL
(or WHILE) statement has to be at the end - better yet,
remove the constraint that there can be only one, thus
making it a synonym for if...break. The existing while
loop, and the repeat...until loop suggested above, are
both special cases of the general loop.

Cheers,

       Bob.



More information about the Python-list mailing list