SA0041: Detect possible loop invariant codePermalink

Detects assignments in loops that calculate the same value for each loop cycle. These lines of code could possibly be inserted outside of the loop.

Justification: This is a performance warning. Code that is executed in a loop, but does the same thing in each loop cycle, can be executed outside of the loop.

Importance: Medium

Example

PROGRAM PLC_PRG
VAR
	iCounter, iVar1, iVar2: INT;
END_VAR

FOR iCounter := 0 TO 10 DO
	iVar1 := 100;		// SA0041
	iVar2 := iVar2 + iVar1;
END_FOR

--> SAN0041: Possible loop invariant code 'iVar1 := 100'