Skip to main content

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

DataDescription
Initial IndexStarting value for the loop index (default: 0).
StepsAmount to increment (positive) or decrement (negative) each iteration (default: 1).
Less ThanUpper bound for ascending loops. Loop continues while index < Less Than. (default: 1)
More ThanLower bound for descending loops. Loop continues while index > More Than. (default: -1)

Actions

SignalDescription
DoInitializes and starts the loop. Resets the index to Initial Index and emits the first Index Updated signal.
Next IterationAdvances the loop to the next step. Must be triggered to proceed.

Outputs

Current State

DataDescription
Current IndexThe current value of the loop index.
IndexAlias for Current Index.

Events

SignalDescription
Index UpdatedTriggered whenever the index changes (including initialization) and the loop condition is still met.
DoneTriggered 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, adds Steps each time Next Iteration is triggered.

Descending Loop (Negative Steps)

  • Setup: Set Steps < 0.
  • Condition: Runs while Index > More Than.
  • Behavior: Starts at Initial Index, subtracts Steps (adds negative value) each time Next Iteration is triggered.

Example Use Cases

  1. Array Processing: Iterate through array elements.
    • Initial Index: 0
    • Steps: 1
    • Less Than: Array Length
    • Connect Current Index to an "Get Array Item" node.
  2. Countdown Timer: Count down from a starting value.
    • Initial Index: 60
    • Steps: -1
    • More Than: -1 (to stop at 0)
  3. Batch Processing: Process items in chunks.
    • Initial Index: 0
    • Steps: 5
    • Less Than: Total Items

Loop Control Flow

  1. Initialization: Trigger Do to start. The Current Index is set to Initial Index, and Index Updated fires immediately.
  2. Processing: Perform your logic (e.g., process array item).
  3. Next Step: When your logic is done, trigger Next Iteration.
  4. Check: The node calculates the new index.
    • If the condition (< Less Than or > More Than) is met: Current Index updates, and Index Updated fires again.
    • If the condition is not met: The loop stops, and Done fires.

Troubleshooting

  • Infinite Loop: If Steps is set to 0, the loop condition will never change, potentially causing an infinite loop if you keep triggering Next Iteration. Ensure Steps is non-zero.
  • Immediate Done: If your Initial Index already fails the condition (e.g., Initial Index 10, Less Than 5), triggering Do will start it, but the first Next Iteration will immediately trigger Done without advancing.
  • Off-by-One Errors: Remember that Less Than is exclusive. If you want to include 10, set Less Than to 11 (or use 10.0001).