I have always avoided using a for-loop index variable after the loop.
I thought its value can be unpredictable in some situations when the
compiler reuses its register or memory etc.

I noticed the ActionListEditor in Lazarus sources has code that uses
it after the loop.
The compiler, FPC 3.0, does not warn about it.
I made a small test:

procedure MyProcedure;
var
  i: Integer;
begin
  for i := 0 to 5 do
    WriteLn('iii ', i);
  Write('After loop i=', i);
  if i = 5 then
    WriteLn(' as expected')
  else
    WriteLn(' which is unpredictable');
end;

Indeed, no warning!
Is it OK to do that? Have I misunderstood it?

Juha
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to