SA0081: Upper border is not a constant

Detects the FOR statements where the upper bound is not defined with a constant value

Justification: If the upper bound of a loop is a variable value, then it is no longer possible to see how often a loop is executed. This can result in serious problems at runtime. The worst case is an infinite loop.

Importance: High

Example

PROGRAM PLC_PRG
VAR
        i:INT;
        iBorder1: INT := 10;
        iBorder2: INT := 10;
        iCounter: INT;
END_VAR
VAR CONSTANT
        ciBorder:INT := 10;
END_VAR

FOR i:=0 TO 10 DO       //OK
        iCounter := i;
END_FOR

FOR i:=0 TO ciBorder DO // OK
        iCounter := i;
END_FOR

FOR i:=0 TO iBorder1 DO // SA0081
        iCounter := i;
END_FOR

FOR i:=0 TO iBorder2 DO // SA0081
        iCounter := i;
        IF iCounter = 10 THEN
                iBorder2 := 50;
        END_IF
END_FOR

--> SA0081: Obergrenze für eine FOR-Schleife muss ein konstanter Wert sein