1. Subroutine nesting and recursion

1. Subroutine nesting and recursion

The main program can call subroutines, and the called subroutines can continue to call subroutines, forming a nested structure. There is no limit to the number of nested layers, but stack resources are limited. Excessive nesting layers can cause stack overflow, and the PLC will report an error.

The stack resources occupied by nested monolayers are related to the size of the parameters and local variables of the subroutines in this layer.

Allow subroutines to call themselves and form recursive structures. Please be cautious when making recursive calls to avoid infinite recursion scenarios.