[Oberon] EXIT statement?

Douglas G. Danforth danforth at greenwoodfarm.com
Sat Aug 30 07:16:07 CEST 2014


Chris,
Hey, thanks for that code!
I need it!
-Doug

On 8/29/2014 10:02 PM, Chris Burrows wrote:
>> -----Original Message-----
>> From: Diego Sardina [mailto:sardinadiego at gmail.com]
>> Sent: Saturday, 30 August 2014 1:28 AM
>> To: oberon at lists.inf.ethz.ch
>> Subject: Re: [Oberon] EXIT statement?
>>
>> These forms of iteration in Oberon have a precise semantic ...
> Great explanation!
>
>
>> There is always an alternative formulation that doesn't require any of
> those
>> forms and they are often surprisingly better in look, code quality and
>> maintenance.
>>
> My favourite example is code to handle Oberon's nested comments. It goes
> something like this:
>
>
> (* With LOOP / EXITs *)
> PROCEDURE Comment;	
> BEGIN
>    Read(ch);
>    LOOP
>      LOOP
>        WHILE ch = "(" DO Read(ch);
>          IF ch = "*" THEN Comment END
>        END;
>        IF ch = "*" THEN Read(ch); EXIT END;
>        IF EOF() THEN EXIT END;
>        Read(ch)
>      END;
>      IF ch = ")" THEN Read(ch); EXIT END;
>      IF EOF() THEN Mark("unterminated comment"); EXIT END
>    END
> END Comment;
>
>
> (* Without LOOP / EXITs *)
> PROCEDURE Comment;
> BEGIN
>    Read(ch);
>    REPEAT
>      WHILE ~EOF() & (ch # "*") DO
>        IF ch = "(" THEN
>          Read(ch);
>          IF ch = "*" THEN Comment END
>        ELSE Read(ch)
>        END
>      END;
>      WHILE ch = "*" DO Read(ch) END
>    UNTIL (ch = ")") OR EOF();
>    IF ~EOF() THEN Read(ch) ELSE Mark("unterminated comment") END
> END Comment;
>
>
> Regards,
> Chris
>
> Chris Burrows
> CFB Software
> Oberon for Cortex-M4, Cortex-M3 and ARM7.
> http://www.astrobe.com
>
>
>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>




More information about the Oberon mailing list