SA0001: Unreachable code

Function

Determines code that is not executed, for example due to a RETURN or CONTINUE statement.

Reason

Unreachable code should be avoided in any case. The check often indicates the presence of test code, which should be removed.

Importance

High

PLCopen rule

CP2

Sample 1 – RETURN:

PROGRAM MAIN
VAR
    bReturnBeforeEnd : BOOL;
END_VAR
bReturnBeforeEnd := FALSE;
RETURN;
bReturnBeforeEnd := TRUE;        // => SA0001

Sample 2 – CONTINUE:

FUNCTION F_ContinueInLoop : BOOL
VAR
    nCounter  : INT;
END_VAR
F_ContinueInLoop := FALSE;
 
FOR nCounter := INT#0 TO INT#5 BY INT#1 DO
    CONTINUE;
    F_ContinueInLoop := FALSE;   // => SA0001
END_FOR