[fpc-pascal] Illegal counter variable?
    James Richters 
    james at productionautomation.net
       
    Mon Sep  9 14:38:40 CEST 2019
    
    
  
>That page only talks about assigning the loop var *inside* the loop, which is forbidden.
You can re-assign the loop variable if you are in {$Mode TP} it works perfectly fine to re-assign the for variable inside the loop, and I use that extensively, I have TP units specifically so I can do that.  I really don't understand why it's forbidden if you aren't in TP mode...  programmers can take care of their own variables and don't need to be protected from themselves.  I have good reasons to want to change the for loop variable and never have a problem with it.  I know there are ways around it, but I prefer to just modify the for variable... it can be very powerful.
This works great! 
{$MODE TP}
Var
   I:Byte;
Begin
  I:=57;
  For I := I to 100 do
    Begin
       If I=87 then
          I:=95;
       Write(I,' ');
    End;
End.
Output:
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 95 96 97 98 99 100
James
    
    
More information about the fpc-pascal
mailing list