30. Repeat a counted sequence with For Loop
Figure 21. For Loop has LOOP and DONE outputs. The body must return to the loop node.
1. Create pulse_count and loop_index as number variables.
2. Set pulse_count to 0 before entering the loop.
3. Add For Loop. Set Iterations to 3 and Index Variable to loop_index.
4. Connect LOOP to Change Variable: pulse_count add 1.
5. Continue through a visible beacon on/off sequence, with a short Wait after each change.
6. Connect the last body node back to For Loop FLOW. Connect DONE to a final restore or Return node.
| Visit | Index / behavior |
|---|---|
| First body | loop_index = 0 |
| Second body | loop_index = 1 |
| Third body | loop_index = 2 |
| Next visit to For Loop | DONE; the body no longer runs. |
The loop counter belongs to this graph invocation and loop-node ID. The Index Variable is a runtime variable you can inspect or use. At the end of a three-iteration loop, its last written index is 2; it is not automatically changed to 3.
Without the return wire, the body runs once and the graph follows whatever route you connected after it. The loop node must be revisited to decide whether another iteration is due.
