SA0072: Invalid uses of counter variablePermalink

Detects the use of a counter variable in a ‎FOR‎ loop

Justification: Manipulation of the counter variable in a ‎FOR‎ loop can easily result in an infinite loop. To prevent the execution of the loop for specific values of the counter variable, use ‎CONTINUE‎ or simply an ‎IF‎.

Importance: High

PLCopen rule: L12

Example

PROGRAM PLC_PRG
VAR_TEMP
	iIndex : INT;
END_VAR
FOR iIndex := INT#0 TO INT#20 BY INT#1 DO
	iIndex := iIndex - INT#1;
END_FOR

--> SA0072: Invalid use of counter variable 'iIndex'