Configuration | Rules nMax1 : INT := 10; nMax2 : INT := 10; END_VAR FOR nIndex := 0 TO 10 DO // no error nVar := nIndex; END_FOR FOR nIndex := 0 TO cMax DO // no error nVar := nIndex; END_FOR FOR nIndex := 0 TO nMax1 DO // => SA0081 nVar := nIndex; END_FOR FOR nIndex := 0 TO nMax2 DO // => SA0081 nVar := nIndex; IF nVar = 10 THEN nMax2 := 50; END_IF END_FOR 4.2.1.5.2 SA0090: POUs should have a only one exit point | SA0090: POUs should have a only one exit point Sample: FUNCTION F_TestFunction : DINT VAR_INPUT bTest : BOOL; END_VAR IF bTest THEN RETURN; // => SA0090 END_IF F_TestFunction := 99; 4.2.1.5.3 SA0095: Assignments in conditions | SA0095: Assignments in conditions Samples:
PROGRAM MAIN VAR bTest : BOOL; bResult : BOOL; bValue : BOOL; b1 : BOOL; n1 : INT; n2 : INT; nCond1 : INT := INT#1; nCond2 : INT := INT#2; bCond : BOOL := FALSE; TE1200 55 Version: 2.11.1 Function Detects code positions where the RETURN statement is not the last statement in a function, method, property or program. It also recognizes places where there is a RETURN within an IF branch. Reason A RETURN in the code leads to poorer maintainability, testability and readability of the code. A RETURN in the code is easily overlooked. You must insert code, which should be executed in any case when a function exits, before each RETURN. This is often overlooked.
Importance Medium PLCopen rule CP14 Function Determines assignments in conditions of IF, CASE, WHILE or REPEAT constructs. Reason An assignment (:=) and a comparison (=) can easily be confused. An assignment in a condition can therefore easily be unintentional and is therefore reported. This can also confuse readers of the code. Importance High