Nested Loop Control
Perform a nested loop calculation every scan when enabled and report the total iteration count.
intermediate
Parameters
| Name | Type | Usage | Description |
|---|
| In_Enable | BOOL | Input | 1 enables the loop execution logic. |
| Out_TotalIterations | DINT | Output | The total number of inner loop iterations completed in the current scan. |
Behavior
- On every scan, if In_Enable is 1, execute a nested FOR loop.
- The outer loop index 'i' ranges from 0 to 10.
- The inner loop index 'j' ranges from 10 to 100.
- An internal accumulator Count increments by 1 for every execution of the inner loop body.
- Out_TotalIterations is updated to the value of Count after the completion of the loops.
- If In_Enable is 0, Out_TotalIterations remains at 0.
Edge Cases
- The AOI must handle the case where the scan time is increased by the loop complexity.
Constraints
- The nested loop must complete within a single PLC scan.
- Out_TotalIterations will be 1001 when enabled.
Ready to start?
Open this exercise in Rungs Studio, write your solution, then click Test in the toolbar to verify your work against the built-in test cases.