[Oberon] Eliminating RETURN statements
Jörg
joerg.straube at iaeth.ch
Wed Apr 8 05:01:09 CEST 2020
Hi Hans
Here my proposals to make you code examples simpler:
(* Oberon-07 *)
PROCEDURE F (x, y: INTEGER): INTEGER;
IF x < y THEN x := y – x
ELSE x := x – y
END
RETURN x
END F;
In this special case, this is perhaps a little clearer (
PROCEDURE F (x, y: INTEGER): INTEGER; RETURN ABS(x-y) END F;
Your code
(* Oberon-07, right output *)
PROCEDURE Fit (i, j: INTEGER): BOOLEAN;
VAR k: INTEGER; OK: BOOLEAN;
BEGIN
k := 0; OK := TRUE;
WHILE (k <= piecemax[i]) & OK DO
IF p[i][k] THEN
IF puzzl[j + k] THEN OK := FALSE END
END;
INC(k)
END
RETURN OK
END Fit;
My proposal:
PROCEDURE Fit (i, j: INTEGER): BOOLEAN;
VAR k: INTEGER; OK: BOOELAN;
BEGIN
k := 0;
WHILE (k <= piecemax[i]) DO
OK := ~( p[i, k] & puzzl[j + k] ); INC(k)
END
RETURN OK END Fit;
Your code:
(* Oberon-07 *)
(...)
k := j; res := 0; exit := FALSE;
WHILE (k <= size) & (~ exit) DO
IF ~ puzzl[k] THEN res := k; exit := TRUE
ELSE INC(k)
END
END
RETURN res
END Place;
My proposal:
k := j;
WHILE (k <= size) & puzzl[k] DO INC(k) END;
IF k > size THEN k := 0 END
RETURN k
END Place;
Jörg
More information about the Oberon
mailing list