free quality report for PLCopenXML exports

Rules / infinite-loop

WHILE TRUE without EXIT in a PLC: why the controller hangs

A loop with no exit condition never lets the scan finish. The task watchdog trips, and if it is disabled the controller stops updating outputs. Long processing in a PLC is spread across scans.

Severity: Critical Rule id: infinite-loop Infinite loop with no exit

What the rule checks

WHILE TRUE / REPEAT … UNTIL FALSE with no EXIT or RETURN inside: the scan never finishes: the task blocks and the watchdog fires (and if the watchdog is off, the controller stalls). In a PLC, long processing is spread across scans, not spun in a loop.

What it does to the plant

Control stops: outputs freeze in their last state and the HMI loses communication.

Example

Bad: the rule fires
PROGRAM WaitReadyVAR    xReady : BOOL;    iTries : INT;END_VARWHILE TRUE DO    iTries := iTries + 1;END_WHILE
Fixed: the rule is silent
PROGRAM WaitReadyVAR    xReady : BOOL;    iTries : INT;END_VARWHILE TRUE DO    iTries := iTries + 1;    IF xReady OR iTries > 10 THEN        EXIT;    END_IFEND_WHILE

Both listings are run through the linter by an automated test: the rule fires on the first and stays silent on the second.

How to fix

  1. Add an exit condition and EXIT, or bound it with an iteration counter.
  2. Split heavy processing across scans: an infinite loop trips the task watchdog.
Check your project

Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.

Local version on GitHub →

The same linter without uploading a file: command line and GitHub Action.

Related rules

In-depth article

2026-11-26

Processing happens in memory, and the uploaded code is not stored. The tool advises; code changes are up to the engineer (see what the linter can't see). What happens to your code → · Rule reference · Your code & privacy · Industry benchmark · Feedback · GitHub