Break
Type: break · Package: Core Activities v1.0.8
Exits immediately the loop (For Each, For Loop or While) that contains it, without finishing the remaining passes. Execution continues with the activity that comes after the loop. Use it when you found what you were looking for or a condition makes further iterations unnecessary.
How it works
Section titled “How it works”When it runs, it interrupts the nearest loop around it. It usually goes inside an If so it only exits under a certain condition.
- It passes through the blocks between it and the loop: an If, a Try / Catch (it does not trigger the
catch, but thefinallyruns) or a Retry (it does not count as a failed attempt). - It does not pass through an Invoke Playbook: a Break inside an invoked playbook does not exit the loop of the calling playbook.
Required parameters
Section titled “Required parameters”None.
Optional parameters
Section titled “Optional parameters”None.
Output
Section titled “Output”This activity does not return a value.
Example
Section titled “Example”Find the first row that meets a condition and stop:
For Each items = table itemVariable = row └─ activities: If condition = str(row["Status"]) == "Approved" └─ then: Set Variable name = found value = row Break // found it: stop loopingLog message = "First approved: " + str(found["Number"])Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
break | A Break ran with no loop around it (or inside an invoked playbook whose loop is in the calling playbook): the execution fails with that message. Move the Break inside the loop; if the invoked playbook needs to request the exit, return it as an output and decide in the parent. |