do...while

François Pinard pinard at iro.umontreal.ca
Thu Jun 20 19:53:46 EDT 2002


[Bjorn Pettersen]

> Doing a quick search over our C++ libraries (~900KLoc), "do {} while()"
> seems to be used in right around 3% of the loops (including while, for;
> excluding recursion).  Seems like overkill to add special syntax for a
> feature used so rarely...

Some of you might remember C.A.R. Hoare's axiomatisation of Pascal, which
also gives good insight for many other languages.  The `do {} while()' was
called `repeat' in Pascal.  The axiom for `while' is one of the simplest
of the whole language, much simpler than the axiom for `repeat'.

This taught me that there is a theoretical foundation for the popularity of
the `while' construct.  After all, program axiomatisation is nothing more
than the formalisation of programmer's thought when s/he produces a program,
and our intuition naturally drives our thoughts towards simpler concepts.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list