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
PROGRAM WaitReadyVAR xReady : BOOL; iTries : INT;END_VARWHILE TRUE DO iTries := iTries + 1;END_WHILE
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
- Add an exit condition and
EXIT, or bound it with an iteration counter. - Split heavy processing across scans: an infinite loop trips the task watchdog.
Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.
The same linter without uploading a file: command line and GitHub Action.
Related rules
In-depth article
2026-11-26