# Control flow

> Control flow nodes that branch (Decision, Switch), iterate (Loop), and merge paths to manage process execution order.

## What it is

Control flow determines how your process decides what to execute and in what order. Every process starts as a straight line of nodes, but real work requires decisions, repetition, and reunification. Flow provides four control flow nodes — Decision, Switch, Loop, and Merge — that let you branch, iterate, and converge without leaving the canvas.

## Branching

Branching splits a process into separate paths so different nodes run depending on a condition.

### Decision — two paths

The Decision node evaluates a single JavaScript expression and routes to one of two outputs: true or false. It fits yes/no, pass/fail, or any binary check.

```javascript
$vars.httpRequest1.output.statusCode === 200
```

The expression above sends successful responses down the true branch and everything else down the false branch.

Refer to the [Decision node reference](node-decision.md) for the full configuration.

### Switch — three or more paths

The Switch node evaluates an ordered list of case expressions and takes the first match. Add up to ten cases plus an optional default branch for anything that doesn't match.

Switch fits routing by category, status, or any value with more than two possible outcomes.

Refer to the [Switch node reference](node-switch.md) for the full configuration.

## Loops

Loops repeat a sequence of nodes multiple times. Flow offers two loop nodes for different situations.

### Loop (For Each)

The Loop node iterates over a collection (an array) and executes its body once per item. It exposes three variables inside the loop body:

- `currentItem` — the item for the current iteration
- `currentIndex` — a zero-based index tracking which iteration is running
- `collection` — the full array being iterated

After all iterations complete, the Loop produces an `output` array that aggregates the results from every iteration. Execution continues from the **success** handle.

A Loop node's **Collection** expression points to the array it iterates over, such as `$vars.script1.output`. The **Parallel** option runs all iterations at the same time instead of sequentially. Nodes connected to the **loop** output handle form the loop body, and the node connected to the **success** handle runs after all iterations complete.

![Loop node on the canvas with a Script node inside the loop body and Script 2 connected to the continue handle, fed by a Manual Trigger and HTTP Request.](https://dev-assets.cms.uipath.com/assets/images/maestro/flow-loop-c9b77065.webp)

## Merging branches

After a Decision or Switch splits your process, use a Merge node when downstream nodes must run regardless of which branch was taken.

The Merge node accepts multiple incoming edges on its single input handle and produces one output. The last node of each branch connects to the Merge, and the process continues from the Merge output handle.

![Decision node with True and False branches, each containing a Script node, both converging into a Merge node that connects to a downstream Script node.](https://dev-assets.cms.uipath.com/assets/images/maestro/flow-decision-branching-3e18f6b6.webp)

:::note
Merge waits for the branch that actually executed — it doesn't wait for all incoming edges. Only the branch that received data during the current run passes through.
:::

## Practical example

Consider a process that fetches a list of support tickets, loops over each one, and routes high-priority tickets differently from the rest.

The process wires together five nodes:

1. An **HTTP Request** node calls a ticket API and returns an array of ticket objects.
2. A **Loop** node iterates over `$vars.httpRequest1.output.body.tickets`.
3. Inside the loop body, a **Decision** node evaluates `$vars.loop1.currentItem.priority === "high"`. The true branch connects to a **Send Email** node that alerts the on-call team; the false branch connects to a **Script** node that logs the ticket for later review.
4. A **Merge** node connects both branches so the iteration completes cleanly regardless of which path ran.
5. The Merge connects back to the Loop's **loopBack** input, and the Loop's **success** handle continues to the rest of the process.

![Canvas showing a complete loop pattern: an HTTP Request feeding into a Loop, with a Decision inside the loop body branching to High priority and Low priority Script nodes, both converging at a Merge, with the Loop continue handle connecting to a final node.](https://dev-assets.cms.uipath.com/assets/images/maestro/flow-complete-loop-793bb2a5.webp)

This pattern — fetch, loop, branch, merge — covers a large portion of real-world automation scenarios.

## Related pages

- **[Decision node](node-decision.md)** — full configuration reference for two-path branching
- **[Switch node](node-switch.md)** — full configuration reference for multi-path branching
- **[Variables and data flow](variables-and-data-flow.md)** — how `$vars` expressions and node outputs work
- **[Error handling](flow-error-handling.md)** — handling failures, which is distinct from conditional branching
- **[The canvas](canvas-overview.md)** — navigating and building processes visually
