[Oberon] Understanding Oberon07's WHILE loops

Chris Burrows chris at cfbsoftware.com
Sat Mar 7 00:31:41 CET 2015


> -----Original Message-----
> From: chris [mailto:chris at gcjd.org]
> Sent: Saturday, 7 March 2015 7:56 AM
> To: oberon at lists.inf.ethz.ch
> Subject: [Oberon] Understanding Oberon07's WHILE loops
> 
> Hello,
> 
> is the following understanding correct, that given conditions c1/c2
> and statement sequences s1 and s2:
> 
> WHILE c1 DO
>   s1
> ELSIF c2 DO
>   s2
> END;
> 
> is equivalent to this code:
> 
> LOOP
>   IF c1 THEN s1
>   ELSIF c2 THEN s2
>   ELSE EXIT END
> END;
> 
> The reason I am unsure is the wording in Wirth's "Differences between
> Revised Oberon and Oberon" where it says:
> "As long as any of the Boolean expressions yields TRUE, the
> corresponding statement sequence is executed."
> 
> In my understanding only at most one statement sequence per iteration
> is executed and that is the first one for which the condition is
> true.
> 

Yes - your understanding is correct. However I find it easier to understand
the operation of the Oberon-07 WHILE loop by rewriting your LOOP as a
conventional WHILE loop (also still legal in Oberon-07):

  C0 := FALSE;
  WHILE C0 DO 
    IF C1 THEN 
      S1
    ELSIF c2 THEN 
      S2
    ELSE 
      C0 := FALSE
    END
  END;

You can now see that the Oberon-07 extended WHILE loop uses the keyword DO
instead of THEN and automatically takes care of the housekeeping associated
with the additional control variable C0.

As an example of the extended WHILE:

  i := 0;
  WHILE i < 3 DO
    INC(i);
    Out.Char("A"); Out.Int(i, 3); Out.Ln;
  ELSIF i < 6 DO
    INC(i);
    Out.Char("B"); Out.Int(i, 3); Out.Ln;
  END

Produces the following output:

  A  1
  A  2
  A  3
  B  4
  B  5
  B  6

Regards,
Chris Burrows

CFB Software
Astrobe: Oberon-07 for ARM Cortex-M3 and M4 Microcontrollers
http://www.astrobe.com





More information about the Oberon mailing list