[Oberon] [Component Pascal]

Richard Hable informujo at aon.at
Sun Feb 17 13:36:19 CET 2013


On 02/16/13 22:11, Claudio Nieder wrote:

> The statement
> FOR v := beg TO end BY step DO statements END
>
> is equivalent to
>
> temp := end; v := beg;
> IF step > 0 THEN
> 	WHILE v <= temp DO statements; INC(v, step) END
> ELSE
> 	WHILE v >= temp DO statements; INC(v, step) END
> END

Yes, this is also the definition in the Oberon-2 language report.

> But I wouldn't wonder if the actual implementation would more resemble to
>
> temp := end; temp2 := beg;
> IF step > 0 THEN
> 	WHILE temp2 <= temp DO v:=temp2; statements; INC(temp2, step) END
> ELSE
> 	WHILE temp2 >= temp DO v:=temp2; statements; INC(temp2, step) END
> END

In this case the compiler would not conform to the language specification.

The behaviour of the FOR loop can, however, really differ depending on 
the compiler in the following case:

VAR v: INTEGER;
...
FOR v := 1 TO MAX(INTEGER) DO ... END;

The program may either loop forever or terminate due to a recognized 
overflow condition in INC(v,1). However, this does not mean that the 
FOR loop is ill-defined. The language definition simply does not 
specify if and when arithmetic overflows have to be checked. Thus, the 
same situation can occur with other loops constructs.

Richard




More information about the Oberon mailing list