UiPath Documentation
maestro-automate
latest
false
Maestro Automate user guide

Control flow

Control flow: which node to choose when a workflow must decide, repeat, or wait for parallel paths, with an example that uses all four together.

Control flow determines how a workflow decides what to run and in what order. A workflow starts as a straight line of nodes, but real work requires decisions, repetition, and rejoining paths. Four control flow nodes cover these needs: Decision, Switch, Loop, and Merge. They branch, repeat, and rejoin paths without leaving the canvas.

Branching​

Branching splits a workflow 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 or no questions, pass or fail checks, and any other check with two outcomes.

$vars.httpRequest1.output.code === 200
$vars.httpRequest1.output.code === 200

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

The Decision node reference describes 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. The Switch node reference describes the full configuration.

Loops​

A loop repeats a sequence of nodes once for each item in a collection.

Loop (For Each)​

The Loop node iterates over a collection, which is an array, an ordered list of values, and runs its body once per item. It exposes three variables inside the loop body:

  • currentItem: the item for the current iteration.
  • currentIteration: the number of the current iteration.
  • collection: the full array being iterated.

After all iterations complete, the Loop produces an output array that aggregates the results from every iteration, and the workflow continues from the node connected to the Loop's output handle on the right edge.

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. The Loop appears on the canvas as a container, with a start handle and a continue handle inside it. Nodes placed between them form the loop body, and the continue handle ends each iteration.

Exit a loop early​

A Loop node offers two ways to stop before it reaches the end of the collection:

  • Break on condition is an expression that the loop checks after each iteration completes. When it's true, the loop stops, and the workflow continues after the loop. Because the check happens after each iteration in order, it works only in sequential loops.
  • The break handle appears inside the loop when Show break handle is on. When a path in the loop body reaches it, the loop stops iterating. The break handle is available in both sequential and parallel loops. Use it when a node in the body makes the decision, for example a Decision that finds the item you're looking for.

Loop describes both settings, with an example.

Merging branches​

A Merge node rejoins parallel branches. It waits for every incoming branch to finish before the workflow continues, and it accepts multiple incoming edges on its single input handle.

The branches of a Decision or Switch are mutually exclusive, because only one of them runs. They do not need a Merge, and a Merge after them would keep waiting for the branch that did not run. Merge describes how it behaves.

Practical example​

A workflow that fetches a list of support tickets, loops over each one, and routes high-priority tickets differently from the rest uses 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, which comes from an email connector such as Amazon SES, that alerts the on-call team; the false branch connects to a Script node that logs the ticket for later review.
  4. Both branches connect to the Loop's continue handle, so the iteration ends whichever path ran.
  5. After all iterations, the node connected to the Loop's output handle continues the rest of the workflow.

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

Next steps​

  • Branching​
  • Decision: two paths​
  • Switch: three or more paths​
  • Loops​
  • Loop (For Each)​
  • Exit a loop early​
  • Merging branches​
  • Practical example​
  • Next steps​

Was this page helpful?

Connect

Need help? Support(opens in new window)

Want to learn? UiPath Academy(opens in new window)

Have questions? UiPath Forum(opens in new window)

Stay updated