A single, general looping construct? (was: why no "do : until"?)

rturpin at my-deja.com rturpin at my-deja.com
Mon Jan 1 11:42:42 EST 2001


In article <x8G36.156$9s1.31209 at e420r-atl2.usenetserver.com>,
  kragen at dnaco.net (Kragen Sitaker) wrote:
> I would want to outdent it because, in my view, it isn't
> part of the loop body; it's part of the loop structure
> itself, just like the while 1: at the beginning. ..

Hi, Kragen. I see your reasoning, and it reminds me
of something.

A couple of decades ago, when the programming journals
were full of arguments about the "right" control
statements for structured programming, someone proposed
a single iteration statement that generalized (a) the
"while" statement, (b) the "do .. until" statement,
and (c) the loop with an exit in the middle. I forget
where the paper appeared, the name of the author, and
the exact syntax. But the core idea, in Pythonic syntax,
would look like this:

    do: <A> while <x>: <B>

Where <A>, and <B> are code blocks, and <x> is the
conditional. With indentation there are three forms:

    # "while" form
    do while <x>:     # In this case, make "do" optional
        <B>
    ..

    # "repeat .. until" form
    do:
        <A>
    while <x>
    ..

    # "exit in the middle" form
    do:
        <A>
    while <x>:
        <B>           # Loop continues at "do"
    ..

I always thought this was a slick solution to the question
of iterative control structures.  If the language allows
repetition of the "while <x>: <B>" in the same loop, this
construct provides multiple exits.  (I mention this, even
though my first reaction to it is: yuch.)  Obviously, the
language could choose to express the exit condition rather
than the loop condition, with a keyword such as "until".

My own view is this: I am plenty happy with "while". If
Guido decides to expand the iteration constructs, I would
prefer to see him think about a generalization of the
"while" statement, rather than adding a second and third.
Keep it simple. Less is better than more. One way to do
everything. Etc.

Mostly, I was experiencing deja vu.  This was a hot topic
back in the old, old days.  I thought if people were going
to discuss it hotly again, they should know about some of
the results from back then.

Russell



Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list