SA0072: Invalid uses of counter variable
Function | Determines write access operations to a counter variable within a FOR loop. |
Reason | Manipulating the counter variable in a FOR loop can easily lead to an infinite loop. To prevent the execution of the loop for certain values of the counter variables, use CONTINUE or simply IF. |
Importance | High |
PLCopen rule | L12 |
Sample:
PROGRAM MAIN
VAR_TEMP
nIndex : INT;
END_VAR
VAR
aSample : ARRAY[1..10] OF INT;
nLocal : INT;
END_VARFOR nIndex := 1 TO 10 BY 1 DO
aSample[nIndex] := nIndex; // no error
nLocal := nIndex; // no error
nIndex := nIndex - 1; // => SA0072
nIndex := nIndex + 1; // => SA0072
nIndex := nLocal; // => SA0072
END_FOR