why no "do : until"?

Carel Fellinger cfelling at iae.nl
Fri Jan 5 20:43:43 EST 2001


r_m_guy at my-deja.com wrote:
...
> The whole "while" and "do:while" thing seems
> arbitrary to me, I think, that there should
> really be one loop construct called "loop:" the

well, it is spelled `while' now, so to keep existing code happy
spell it `while' too *and* allow for the extremely frequent variant
where there are no statements prior to the test.

   while <optional-test>:
      <statements>
      if <test>: <break or even continue>
      <statements>

I wonder what's wrong with this idea?  (no-one has ever, to my
knowledge, objected to it, neither has it found many fans:)

It would remove the ugly always-true test in the `while 1:' idiom for
*all* non-common loop-forms.  It would be fully compatible with
current code.  The only thing left to satisfy anybody (Alex) would be
to dedent the if-guard.

Fortunately there is no common opinion on what forms a statement-suite:
to some all statements, including the if-guard, form while's-statement-suite;
to others the if-guard is of such importance that they allow it to
break the indentation of the statements in while's-statement-suite.
So we just pick one and we all win, no code breakage and *Knuth's*
general loop construct finally added to Python hence no more
endless discussions on this subject:)

> All this approach does is replace the artificial
> contruct "while 1" with a single natural "loop"
> construct.

> Just my 2 cents, but it seems sensible to me.

me to.
-- 
groetjes, carel



More information about the Python-list mailing list