Skip to content

How loops work ​

A loop repeats a section of a workflow multiple times, each time with different input. Instead of building separate branches for each variation — each file, each row, each parameter — you build one branch and let the loop feed it different data on each pass.

The structure of a loop ​

Every loop has three parts:

  • Loop Start node — defines what changes each iteration and sends data to the loop body
  • Loop body — executes sub-workflow steps; these run once per iteration
  • Loop End node — collects the result from each iteration and decides whether to continue or stop

The Loop Start and Loop End nodes are paired for different types of loops, each start node type has a corresponding end node designed to work with it.

What changes each iteration ​

Loops differ by what they vary:

PatternWhat changesTypical use
ChunkA batch of rows from a tableProcessing large tables that don't fit in memory at once
Row-by-rowOne row converted to flow variablesApplying node settings that differ per row
CountingAn integer counterRunning a fixed number of experiments or retries
GroupA subset of rows sharing a column valueProcessing each customer, product, or category separately
RecursiveThe output of the previous iterationConverging computations, building up results incrementally
Column listOne column at a timeApplying the same transformation to multiple columns

When to use a loop — and when not to ​

Loops are powerful but not always the right tool. Knime has many nodes that operate on multiple columns or groups directly, using them avoids loop overhead entirely.

Use a loop when:

  • Each iteration depends on the result of the previous one (for example, iterating until a model converges, or paging through an API until no more results come back)
  • Each iteration requires a different node configuration, not just different data, and the node can’t read that setting from a column (for example, a different file path per row for a node that can’t read multiple files at once)
  • Each item needs logic a single node can’t express, such as custom retries or branching per call

Prefer a non-loop alternative when:

  • You’re applying a calculation to every row — nodes like Math Formula, String Manipulation, Rule Engine, and Expression already process all rows
  • You’re applying the same transformation to multiple columns — use multi-column variants of manipulation nodes
  • You’re aggregating groups of rows — use GroupBy, Pivot, or DB GroupBy directly

If you do need a loop over independent items, consider the Parallel Chunk Start and Parallel Chunk End nodes to run iterations in parallel. This helps most when the wrapped nodes are slow and single-threaded or wait on I/O.

How results are collected ​

The Loop End node runs at the end of every iteration. It collects that iteration’s output, and after the last iteration it outputs the assembled result:

  • Most Loop End nodes concatenate tables row-wise — useful when each iteration produces a subset of the final table
  • The Loop End (Column Append) variant joins outputs column-wise
  • The Variable Loop End collects flow variables instead of tables, and outputs one row per iteration with the selected variables as columns — useful when the loop body has no data output, for example when each iteration only writes a file

Row-wise Loop End nodes can add an iteration column to show which iteration produced each row. If iterations produce tables with different columns or column types, enable the options that allow changing table specifications — otherwise the loop fails.

Flow variables and loops ​

Flow variables connect naturally with loops. The Table Row to Variable Loop Start node converts each row of a table into flow variables for that iteration — every column becomes a variable the loop body can use to configure downstream nodes.

Be careful with variable names in loops: if two branches of the loop body create a variable with the same name, only one value survives where the branches merge, and which one depends on the port order, not on which branch ran last. Give variables unique names to avoid this.

Variables created inside the loop body don’t automatically leave the loop. To pass them on after the loop finishes, enable “Propagate modified loop variables” in the Loop End node.

Error handling in loops ​

If a node inside a loop body fails, execution stops at that node and the loop never finishes. Wrap the error-prone section in a Try-Catch enclosure, with both the Try and Catch Errors nodes inside the loop body, so the loop can continue to the next iteration.

Catch Errors passes on an alternative input when the protected section fails. This alternative table must have the same columns as the normal output, or the Loop End fails. The error details, such as the failing node and its message, are available as flow variables if you want a log of what failed you can collect them, for example with Variable to Table Row.