Loop
This node creates controllable loops with customizable iteration logic.
The Loop node provides iteration control with configurable start values, steps, and termination conditions.
The Loop node enables the creation of controlled iteration sequences. It maintains an index that can be incremented or decremented by specified steps, with configurable termination conditions for creating both ascending and descending loops.
Inputs
Loop Configuration
| Data | Description |
|---|---|
| Initial Index | Starting value for the loop index (default: 0). |
| Steps | Amount to increment (positive) or decrement (negative) each iteration (default: 1). |
| Less Than | Upper bound for ascending loops. Loop continues while index < Less Than. (default: 1) |
| More Than | Lower bound for descending loops. Loop continues while index > More Than. (default: -1) |
Actions
| Signal | Description |
|---|---|
| Do | Initializes and starts the loop. Resets the index to Initial Index and emits the first Index Updated signal. |
| Next Iteration | Advances the loop to the next step. Must be triggered to proceed. |
Outputs
Current State
| Data | Description |
|---|---|
| Current Index | The current value of the loop index. |
| Index | Alias for Current Index. |
Events
| Signal | Description |
|---|---|
| Index Updated | Triggered whenever the index changes (including initialization) and the loop condition is still met. |
| Done | Triggered when the loop termination condition is met (i.e., the loop is finished). |
Usage
The Loop node provides flexible iteration control. Unlike a standard for loop that runs all at once, this node waits for a Next Iteration signal to advance, making it perfect for asynchronous operations, animations, or step-by-step processing.
Loop Types
Ascending Loop (Positive Steps)
- Setup: Set
Steps> 0. - Condition: Runs while
Index < Less Than. - Behavior: Starts at
Initial Index, addsStepseach timeNext Iterationis triggered.
Descending Loop (Negative Steps)
- Setup: Set
Steps< 0. - Condition: Runs while
Index > More Than. - Behavior: Starts at
Initial Index, subtractsSteps(adds negative value) each timeNext Iterationis triggered.
Example Use Cases
- Array Processing: Iterate through array elements.
Initial Index: 0Steps: 1Less Than: Array Length- Connect
Current Indexto an "Get Array Item" node.
- Countdown Timer: Count down from a starting value.
Initial Index: 60Steps: -1More Than: -1 (to stop at 0)
- Batch Processing: Process items in chunks.
Initial Index: 0Steps: 5Less Than: Total Items
Loop Control Flow
- Initialization: Trigger Do to start. The
Current Indexis set toInitial Index, andIndex Updatedfires immediately. - Processing: Perform your logic (e.g., process array item).
- Next Step: When your logic is done, trigger Next Iteration.
- Check: The node calculates the new index.
- If the condition (
< Less Thanor> More Than) is met:Current Indexupdates, andIndex Updatedfires again. - If the condition is not met: The loop stops, and Done fires.
- If the condition (
Troubleshooting
- Infinite Loop: If
Stepsis set to0, the loop condition will never change, potentially causing an infinite loop if you keep triggeringNext Iteration. EnsureStepsis non-zero. - Immediate Done: If your
Initial Indexalready fails the condition (e.g.,Initial Index10,Less Than5), triggeringDowill start it, but the firstNext Iterationwill immediately triggerDonewithout advancing. - Off-by-One Errors: Remember that
Less Thanis exclusive. If you want to include 10, setLess Thanto 11 (or use 10.0001).