Re: Catching Break?

From: Pierre Weis (
Date: Tue Feb 09 1999 - 09:43:46 MET

From: Pierre Weis <>
Message-Id: <>
Subject: Re: "while" with condition at end?
To: (Markus Mottl)
Date: Tue, 9 Feb 1999 09:43:46 +0100 (MET)
In-Reply-To: <> from "Markus Mottl" at Feb 8, 99 09:14:47 pm

> Hello!
> I have just found out that there is no loop construct that checks the
> termination condition at the end of the block. Is there some special
> reason to this?
> I'd like to write something like e.g.
> do
> ();
> ...;
> while (some_condition);
> The only work-around is to either double the code and execute it once
> before a "normal" while-loop (not elegant). The other option is to put
> the block into a unit-function (a bit less efficient) and use it once
> before and than in the loop (also not very elegant).
> A construct of this kind would probably make the imperative features
> more complete.
> Best regards,
> Markus Mottl
> --
> Markus Mottl,,

The introduction of a ``do ... while ...'' construct would introduce
ambiguities in the Caml grammar. It would be preferable to
introduce a new keyword for the new kind of loop, for instance


Or may be better, just change the keyword ``while'' into the keyword
``until'' to reflect the symetry between the two syntactic constructs
for imperative loops:

until cond

For the time being, there is a simple workaround (admittedly not as
nice as desirable): merge the ``actions'' and the ``condition'' into a
single sequence within a while loop with an empty body. In effect,

until cond

is equivalent to

while actions; cond do () done

Alternatively, you may define your loop via a recursive function:

let rec repeat_loop () =
 if not cond then repeat_loop () in
repeat_loop ()

Best regards,

Pierre Weis

INRIA, Projet Cristal,,

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:19 MET