[Oberon] Eliminating RETURN statements
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Thu Apr 9 08:38:21 CEST 2020
> Here is an alternative:
>
> PROCEDURE Fit (i, j: INTEGER): BOOLEAN;
> VAR k: INTEGER;
> BEGIN
> k := 0;
> WHILE (k <= piecemax[i]) & ~(p[i, k] & puzzl[j + k]) DO
> INC(k)
> END ;
> RETURN k > piecemax[i]
> END Fit;
>
Another variant, which takes into account that piecemax[i] is a constant inside the WHILE loop
PROCEDURE Fit (i, j: INTEGER): BOOLEAN;
VAR k, m: INTEGER;
BEGIN k := 0; m := piecemax[i];
WHILE (k <= m) & ~(p[i, k] & puzzl[j + k]) DO INC(k) END ;
RETURN k > m
END Fit;
More information about the Oberon
mailing list