Skip to main content

Compiler Warning C0266

Message: Loop exit condition <condition>' is constant FALSE. Possible endless loop.

Possible error cause: In a FOR loop, iteration takes place over the entire value range of the control variable.

Error correction: In accordance with the IEC 61131 standard, the statements within the FOR loop are executed only when the value of the control variable exceeds the final value. Therefore, use a sufficiently large type for the control variable which can map the final value+1.

Example 462. Example of the warning
PROGRAM PLC_PRG
VAR
      b : BYTE;
      i : INT;
END_VAR
FOR b := 0 TO 255 BY 1 DO
      i := i + 1;
END_FOR;

Message

C0266: Loop exit condition 'b > 255' is constant FALSE. Endless loop possible.