In Delphi, consider
var
i: integer;
begin
for i := 0 to N do
begin
{ Code }
end;
One might think that i = N
after the for
loop, but does the Delphi compiler guarantee this? Can one make the assumption that the loop variable is equal to its last value inside the loop, after a Delphi if
loop?
Update
After trying a few simple loops, I suspect that i
is actually equal to one plus the last value of i
inside the loop after the loop... But can you rely on this?
for
loop? I would check this first - because I suspect it may not be. – ClaspingN
will be in scope after the loop because it was obviously in scope before the loop (or else the code wouldn't have compiled). Scope in Delphi doesn't change mid-function; it starts at the start of a function and ends at the end. – Filly