From: Pierre Weis <Pierre.Weis@inria.fr>
To: mottl@miss.wu-wien.ac.at (Markus Mottl)
Cc: caml-list@inria.fr
Subject: Re: "while" with condition at end?
Date: Tue, 9 Feb 1999 09:43:46 +0100 (MET) [thread overview]
Message-ID: <199902090843.JAA22736@pauillac.inria.fr> (raw)
In-Reply-To: <199902082014.VAA24823@miss.wu-wien.ac.at> 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, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~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
repeat
actions
until
cond
done
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
do
actions
done
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
do
actions
done
is equivalent to
while actions; cond do () done
Alternatively, you may define your loop via a recursive function:
let rec repeat_loop () =
actions;
if not cond then repeat_loop () in
repeat_loop ()
Best regards,
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/
prev parent reply other threads:[~1999-02-09 8:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-02-08 20:14 Markus Mottl
1999-02-09 8:43 ` Pierre Weis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199902090843.JAA22736@pauillac.inria.fr \
--to=pierre.weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=mottl@miss.wu-wien.ac.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox