I would not mind dropping the feature. The ISO Standard, IIRC, does not allow it.
It may seem to be a useful feature at first sight (in particular using a field in a record as control variable, where there is less harm), but it does not save much and, as the example shows, encourages obscurity. Even if the identity of the control variable is determined only once (just like the upper bound), it is still a bigger burden to understand such a construction.
On the other hand, even with simple control variables (that are not changed inside the for-loop), you can write obscure code:
readln ( i ) ; for i := i + 1 to sqr ( i ) do write ( i )
Exercise: Determine the output for various input values of i by reasoning (rather than trying).
Tom -- On Wed, Jun 29, 2005 at 08:19:06AM +0200, Frank Heckenbach wrote:
GPC accepts the following program, but produces quite silly results:
program Foo;
var a: array [1 .. 2] of Integer value (0, 0); i: Integer;
begin i := 1; for a[i] := 1 to 10 do begin WriteLn (i, ' ', a[i]); if a[i] = 5 then i := 2 end end.
The problem is that it evaluates the index i each time, not once before the loop. It would be possible to fix it, but do we really want that? Neither BP nor CP/EP allow it, they allow only identifiers in for-loops.
Waldek and I see no need for such a feature. (If it made it possible to nest a compile-time-unknown number of `for' loops, I could see some point, but of course, it doesn't.)
So, would anybody mind dropping this misfeature, and requiring an identifier in for-loop counters?