[Oberon] LOOP conversion

Chris Burrows chris at cfbsoftware.com
Mon Jan 4 22:36:52 CET 2021


> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> Michael Schierl
> Sent: Tuesday, 5 January 2021 7:44 AM
> To: oberon at lists.inf.ethz.ch
> Subject: Re: [Oberon] LOOP conversion
> 
> 
> Am 04.01.2021 um 10:33 schrieb Chris Burrows:
> > Monday, 4 January 2021, Bernhard Treutwein:
> 
> >> Step;
> >> WHILE ~cond DO
> >>    CodeBlock;
> >>    Step
> >> END
> >>
> >
> > If an action in a loop is always performed at least once, a REPEAT
> > loop is usually preferable to WHILE.
> >
> > This then becomes:
> >
> > REPEAT
> >    Step;
> >    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.
> 

Good point! The LOOP was not the only questionable aspect of the original
code. I would have expected 'cond' to be a parameter of Step or CodeBlock or
both to make it clear which was modifying it. Side effects must be avoided
at all costs to avoid these sorts of issues. 

Regards,
Chris

Chris Burrows
CFB Software
https://www.astrobe.com




More information about the Oberon mailing list