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/decrement each iteration (default: 1)
Less ThanUpper bound for ascending loops (default: 1)
More ThanLower bound for descending loops (default: -1)

Actions

SignalDescription
DoStarts the loop, resets index to initial value
Next IterationAdvances to the next iteration

Outputs

Current State

DataDescription
Current IndexCurrent loop index value
IndexAlias for current index
Is RunningBoolean indicating if loop is active

Events

SignalDescription
Index UpdatedTriggered when index changes
Loop CompleteTriggered when loop termination condition is met

Usage

The Loop node provides flexible iteration control for various programming patterns:

Loop Types

Ascending Loop (Positive Steps)

  • Index starts at Initial Index
  • Increments by Steps value each iteration
  • Continues while index < Less Than
  • Useful for: counting up, iterating through arrays

Descending Loop (Negative Steps)

  • Index starts at Initial Index
  • Decrements by absolute Steps value each iteration
  • Continues while index > More Than
  • Useful for: counting down, reverse iteration

Example Use Cases

  1. Array Processing: Iterate through array elements

    Initial Index: 0
    Steps: 1
    Less Than: arrayLength
  2. Countdown Timer: Count down from a starting value

    Initial Index: 60
    Steps: -1
    More Than: -1
  3. Custom Range: Iterate over specific numeric range

    Initial Index: 10
    Steps: 2
    Less Than: 20
    Result: 10, 12, 14, 16, 18
  4. Batch Processing: Process items in chunks

    Initial Index: 0
    Steps: 5
    Less Than: totalItems

Loop Control Flow

  1. Initialization: Call Do signal to start loop
  2. Iteration: Call Next Iteration to advance
  3. Condition Check: Loop automatically checks termination conditions
  4. Completion: Loop Complete signal fires when conditions are met

Advanced Patterns

Nested Loops: Use multiple Loop nodes for nested iteration Conditional Loops: Combine with condition nodes for complex logic Dynamic Bounds: Update Less Than/More Than values during execution Event-Driven: Use Index Updated signal to trigger other operations

State Management

  • Is Running: Tracks whether loop is actively executing
  • Index Persistence: Current index maintained between iterations
  • Reset Behavior: Do signal always resets to Initial Index
  • Safety: Invalid conditions prevent infinite loops

Error Handling

The Loop node includes built-in safety mechanisms:

  • Prevents infinite loops through condition validation
  • Maintains state consistency during execution
  • Handles edge cases like zero steps or invalid bounds

Integration Patterns

With Arrays: Use Current Index to access array elements With Conditions: Check Index value for custom termination logic
With Delays: Add timing between iterations for visual effects With State: Update external state based on current iteration