Loop control vriable in a procedure must be local to that procedure, but this is not documented.
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
A loop control variable in a procedure must be local to that procedure.
It is the same in Delphi.
The documentation does not mention this though.
Steps to reproduce:
program test;
{$ifdef fpc}
{$mode delphi}
{$h+}
{$endif}
procedure Proc;
var
i: integer;
procedure Nested;
//var
// i: integer;
begin
for i := 1 to 2 do ;
end;
begin
end;
begin
end.
The compiler complains: "test.pas(15,9) Error: Illegal counter variable".
(Delphi says: "test.pas(15) Error: For loop control variable must be simple local variable.")
Additional information:
Reported in https://forum.lazarus.freepascal.org/index.php/topic,45270.msg319903.html#msg319903
Mantis conversion info:
- Mantis ID: 35476
- OS: Windows
- OS Build: 10
- Platform: i386
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 1603 (#77529991)
- Target version: 3.2.0