DAG Loop icon

DAG Loop

Loop over an array of items with isolated loop state.

DAG Loop

AI-generated

Summary

Iterate over an array from a specified JSON field in the input, processing items in batches with conditional controls to continue or break the loop. Outputs each batch of looped items with additional index and total count metadata and a final summary when all iterations complete or the loop stops early.

Inputs

  • Source Field (required) — The key of the input JSON that contains the array to be looped over.
  • Batch Size (required) — Number of items to output per iteration; 1 means processing one item at a time.
  • Max Iterations (required) — Maximum number of items to process before forcibly stopping the loop to prevent infinite execution.
  • Index Variable Name (required) — Name of the field added to each output item that holds the current item's zero-based index.
  • Total Variable Name (required) — Name of the field added to each output item indicating the total number of items in the array.
  • Break Condition — An n8n expression evaluated after processing each batch; if it returns true, the loop stops early.
  • Continue Condition — An n8n expression evaluated before processing each item; if it returns false, the iteration is skipped.

Output shape

Two outputs: the first emits batches of looped items enriched with index, total count, and flags for first/last item; the second emits a single summary item when looping completes or stops early.

The loop state persists across executions using workflow static data. Iteration stops when all items are processed, the max iteration limit is reached, or the break condition triggers. The summary output includes metadata about total iterations, items processed, early break status, and source field name.

Links

Discussion