Skip to main content

Loop

Controlled node

Overview

The Loop node executes a workflow branch repeatedly for a specified number of iterations. It is useful for batch processing, repeating operations, or iterating through a fixed number of steps.

On each iteration, the node fires the loop event and outputs the current index (0-based). When all iterations are complete, it fires the finished event.

Output events

There are two output event options for this node:

  • loop: Fires for each iteration while the loop is running. Connect this to the nodes you want to execute repeatedly.
  • finished: Fires once when the loop has completed all iterations. This is useful for triggering cleanup actions or subsequent steps after the loop finishes.

Inputs

InputTypeDescriptionDefault
runEventTriggers the loop to start.-
timesNumberSpecifies the number of times to repeat the loop.0

Outputs

OutputTypeDescription
loopEventFires on each iteration of the loop.
indexNumberContains the current iteration index (0, 1, 2, ..., times-1).
finishedEventFires when the loop has completed all iterations.

Runtime behavior and defaults

When the run event fires, the Loop node begins executing. It maintains an internal counter starting at 0. While the counter is less than the times value, the node:

  1. Sets the index output to the current counter value
  2. Fires the loop event
  3. Repeats (increments the counter)

When the counter reaches the times value, the node fires the finished event and stops. If times is 0 or not a valid number, the node will fire finished immediately without firing loop.

Zero-based indexing

The index output starts at 0 and increments to times - 1. For example, if times is set to 5, the index will output 0, 1, 2, 3, and 4 on successive iterations.

Example

Scenario: Generate 5 variations of a text prompt using an AI Write node.

  1. Connect a Start node to the run input of the Loop node.
  2. Set the times input to 5.
  3. Connect the loop output to an AI Write node.
  4. Connect the index output to the AI Write node's prompt input using template syntax (e.g., "Generate paragraph {{index}}: ...").
  5. Connect the finished output to a Show node to display a "Generation complete" message.

The workflow will run the AI Write node 5 times with indices 0 through 4, then trigger the Show node when finished.