Conditions & Branching
if-this-then-that — behaving differently depending on the situation
4 min read
An app needs to behave differently depending on the situation. When a list is empty, when a request fails, when a number crosses a threshold — handling these cases is what the Conditional action is for. It lets you express "if this, then that" without writing code.
How a Branch Works
A Conditional action looks at a single subject value and runs the first arm whose condition matches. The conditions available depend on the type of the subject value.
Boolean (True/False)
- True — When the value is true
- False — When the value is false
Number
Compares a number against a reference value.
| Operator | Meaning |
|----------|---------|
| == | Equal |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal |
| <= | Less than or equal |
String
- equals — Exact match
- ≠ — Does not match
- contains — Contains
- starts with — Starts with
- ends with — Ends with
HTTP Status Code
When handling the result of an API call, you branch on status code patterns (200, 2XX, 4XX, default). You can also auto-generate branches based on the response statuses declared by that API.
Else
The default arm that runs when none of the conditions match.
What Each Arm Runs
In each arm, you can write the actions to run directly (an inline flow), or reference an existing project Action Flow.
Guard — Stop Unless a Condition Holds
Guard is the early-exit sibling of branching. You give it one subject value and one condition — when the condition holds, the flow continues to the next action; when it doesn't, the flow stops right there (an intended exit, not an error).
- Skip the rest of the flow (saving, API calls) when the input is empty
- Stop right away when the API response isn't
2XX
When all you need is "continue only if…", a Guard is simpler than a Conditional with multiple arms. The condition kinds (Boolean, number, text, HTTP status) are the same as branching.
For Each — Loop Over an Array
For Each iterates over an array, running its body flow once per element, in order.
- Bind the array to iterate.
- Write the actions to run in the body.
- In the body actions, bind For Each's output
{Item, Index}to use the current element and its position.
- Collect results by using Update Data (Append) in the body to add to a destination array.
- A Guard inside the body skips just that iteration (continues with the next element).
- A failure on one element doesn't stop the loop, and iteration is capped at 1,000.
For example, loop over an array of numeric IDs, send an API Call for each ID, and Append the response to a list data — the ID list fills out into a list of details.
Examples
- If the input is empty, show an Alert; otherwise, add the data.
- If the score is
>= 100, navigate to a congratulations screen; in the Else arm, leave it as is. - If the API response is
2XX, bind the result to the screen; if4XX, show an error message. - Put a Guard for "continue only when signed in" at the top of a flow to protect everything after it.
If you want to compare numbers or text to get a true/false value, you can first produce a Boolean value with the Compare / Compare Text actions from Types of Actions, then branch on it.