[Oberon] LOOP conversion
schierlm at gmx.de
Mon Jan 4 22:13:58 CET 2021
Am 04.01.2021 um 10:33 schrieb Chris Burrows:
> Monday, 4 January 2021, Bernhard Treutwein:
>> WHILE ~cond DO
> If an action in a loop is always performed at least once, a REPEAT loop is
> usually preferable to WHILE.
> This then becomes:
> IF ~cond THEN CodeBlock END
> UNTIL cond
Keep in mind that this code is not equivalent in case CodeBlock can have
side effects that modify ~cond.
Then you'd have to do something like
VAR done: BOOLEAN;
done := FALSE;
IF cond THEN
done := TRUE
But I still like it better than the WHILE solution, as it does not
duplicate the Step code.
More information about the Oberon