[Oberon] Tidyness of iteration.
peter at easthope.ca
peter at easthope.ca
Mon Nov 14 19:18:04 CET 2016
(* Pre-2013. *)
PROCEDURE LOOPiteration();
BEGIN
Texts.OpenReader(R, t, 0);
LOOP
Texts.Read(R, ch);
IF R.eot THEN EXIT ELSE (* Process ch *) END
END
END LOOPinteration.
Project Oberon 2013, Page 5.
"2. The LOOP and EXIT statements (repetitions with multiple exit points) have been discarded."
(* Using REPEAT, R.eot must be checked twice in each iteration. *)
PROCEDURE REPEATiteration();
BEGIN
Texts.OpenReader(R, t, 0);
REPEAT
IF ~R.eot THEN Texts.Read(R, ch); (* Process ch *) END
UNTIL R.eot
END REPEATinteration.
(* Using WHILE, Texts.Read is duplicated. *)
PROCEDURE WHILEiteration();
BEGIN
Texts.OpenReader(R, t, 0);
Texts.Read(R, ch);
WHILE ~R.eot
(* Process ch *);
Texts.Read(R, ch)
END
END WHILEinteration.
Can the REPEAT example or the WHILE example be simplified further?
(One must wonder about discarding REPEAT and WHILE and retaining LOOP with
strictly one EXIT.)
Thanks, ... Lyall E.
--
123456789 123456789 123456789 123456789 123456789 123456789 123456789
Tel: +1 360 639 0202 Pender Is.: +1 250 629 3757
http://easthope.ca/Peter.html Bcc: peter at easthope. ca
More information about the Oberon
mailing list