Misfeatures in For loops
Contestcen at aol.com
Contestcen at aol.com
Sun Jul 17 06:46:22 CEST 2005
>> 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.
>
> Neither do I.
>
> Nor I. I vaguely recall that it is forbidden in at least ISO 7185,
> but cannot quote chapter and verse. This is a milestone, where BP
> is more standards adherent :=)
I have come in late to this discussion, and I am not sure what is the
supposed "misfeature." Are the participants saying that Borland Pascal does not
accept an array element as the control variable of a For loop, and that therefore
GPC should not accept array elements either?
If that is the case, then the premise is incorrect. BP does accept array
elements as control variables. The following program compiles and runs correctly
in BP. It produces the expected result 100.000.
Program Try;
Var
a: array[1..10] of integer;
s: real;
Begin {Try}
s := 0.0;
for a[1] := 1 to 10 do
for a[2] := 1 to 10 do
s := s + 1.0;
writeln (s:10:3);
End. {Try}
Using array elements as control variables is very useful when you want the
ability to stop a deeply nested loop, checkpoint the program, and then resume
the execution from the same point later. I would not like to see this
capability removed.
Frank Rubin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.g-n-u.de/pipermail/gpc/attachments/20050717/d2c9064f/attachment.htm>
More information about the Gpc
mailing list