Re: [ooc-compiler] FOR Loops And Structured Variables
Brought to you by:
mva
|
From: Frank C. <fj...@th...> - 2006-03-20 13:44:37
|
August Karlstrom wrote:
> Why doesn't the following module compile?
>
> MODULE Test;
> VAR a: ARRAY 1 OF LONGINT;
> BEGIN
> FOR a[0] := 0 TO 1 DO END
> END Test.
>
> I've read that in Modula, loop variables in FOR loops cannot come from
> structured variables, but I can't find that restriction in the Oberon-2
> report. Anyway, what's the motivation for the restriction?
From the Oberon-2 Report:
ForStatement = FOR ident ":=" Expression TO Expression
[BY ConstExpression] DO StatementSequence END.
and 'ident' is defined as:
1. Identifiers are sequences of letters and digits. The first character
must be a letter.
ident = letter {letter | digit}.
Examples: x Scan Oberon2 GetSymbol firstLetter
This obviously excludes structured variables as loop variables.
Motivation? You would have to ask Wirth or Gutnecht about that, but my guess
would be disbelief that anyone sensible would use anything other than a
simple integer variable as a loop variable.
--
TONY RANDALL! Is YOUR life a PATIO of FUN??
|