[fpc-devel] Debugging Loop Unroll Optimization

Ondrej Pokorny lazarus at kluug.net
Fri May 18 17:49:21 CEST 2018

On 18.05.2018 17:17, Marco van de Voort wrote:
> To keep in annoying detail mode:
>     for result:=0 to 3 do
>       if x(result) then
>         exit(result)
> ...is yet another case since the exit(result) could be taken as an explicit
> assignment of the loopvar to an location outside the loop, after which the
> loopvar scope ends.

It is a yet another case of what?

AFAICS the above code throws a compiler error: Illegal assignment to 
for-loop variable "$result" - and that is correct because you assign a 
value to a loop variable within a loop.

BTW. it's the same as:
function Test: Integer;
   for Result := 1 to 10 do

gives a compiler error as well, since you assign 5 to loop variable 
within a loop.

The Exit; (without argument) doesn't assign anything - it should just 
exit the current function without touching any of the variables.


More information about the fpc-devel mailing list