Glossary · Automation fundamentals, platforms and components
Recursion
Also known as: Recursive call
German: Rekursion
In programming, recursion is a technique in which a function or procedure calls itself, directly or indirectly, to solve a problem by reducing it to smaller instances of the same problem until a base case is reached.
- Automation components
In one sentence
Recursion means a function calls itself to solve smaller instances of a problem; PLC coding guidelines usually restrict it for timing reasons.
Example
A tool script walks through a nested folder of machine variants recursively, while the PLC code that uses the result contains only loops with fixed bounds.
How it applies
- Engineering: Recursion is natural for tree structures such as nested configurations, bills of material or file systems, and is common in Python tools and IT software.
- Control code: On PLCs, recursion makes stack use and execution time hard to bound, which can overrun the Scan cycle and trigger the Watchdog. IEC 61131-3 does not intend recursive calls, and many environments reject or restrict them; coding guidelines, especially for safety-related software, usually forbid them.
- Documentation: Coding guidelines should state whether recursion is permitted and, if so, the maximum depth. Code reviews check this rule.
Recursion vs. iteration
Every recursive algorithm can be written as a loop (iteration), often with an explicit stack. In control software, iteration with fixed bounds is preferred because its time and memory use are predictable.