Loops and Branching in Cloud Flows
Make your flows smart with conditions, loops, and parallel branches. Learn how Power Automate handles decisions, repeating actions, and running steps side by side.
Why flows need logic
Think of it like driving directions.
βGo straight until you reach the roundabout. If you are going to the hospital, take the second exit. If you are going to the shops, take the third exit.β
Without logic, your flow can only go in a straight line. With conditions and loops, it can make decisions, repeat steps, and handle different situations β just like real driving directions handle different destinations.
Conditions (If/Then/Else)
A Condition action checks whether something is true or false, then runs different actions based on the result.
Structure:
- If yes (true): Run these actions
- If no (false): Run these actions
Carlosβs conditional routing
When a patient feedback form is submitted at Greenleaf Health, Carlos wants different things to happen based on the rating:
- If the rating is 4 or 5: Send a thank-you email to the patient
- If the rating is 1, 2, or 3: Send an alert to the clinic manager and create a follow-up task in Planner
One flow, two different paths. The condition decides which path to take.
Nesting conditions
You can put a condition inside another condition β this is called nesting. For example:
- If rating is 5: Send thank-you and ask for a Google review
- Else if rating is 4: Send thank-you only
- Else if rating is 3: Send to manager
- Else: Send to manager AND director
While nesting works, too many levels make flows hard to read. For multiple specific values, use a Switch instead.
Switch
A Switch action checks a value and runs different actions based on which case it matches. Think of it as a more organised version of multiple nested conditions.
| Rating Value | Action |
|---|---|
| Case: 5 | Send thank-you, request review |
| Case: 4 | Send thank-you |
| Case: 3 | Alert clinic manager |
| Case: 2 | Alert manager, create task |
| Case: 1 | Alert manager and director, create urgent task |
| Default | Log an error (unexpected value) |
Switch vs Condition: Use a Condition when you have a true/false check. Use Switch when you have multiple specific values to match against. Switch keeps your flow cleaner than deeply nested conditions.
Apply to Each (Loops)
Apply to each repeats a set of actions for every item in a list or array.
Example: Carlos sends personalised emails
Carlos gets a list of 20 patients who have appointments tomorrow. He needs to send each one a reminder email with their specific appointment time.
Instead of building 20 separate email actions, he uses Apply to each:
- Get items from the Appointments SharePoint list (returns 20 rows)
- Apply to each item in the list:
- Action: Send an email to the patient with their name and appointment time
The flow runs the email action 20 times β once for each patient. If there are 5 patients tomorrow, it runs 5 times. If there are 100, it runs 100 times. The loop adapts automatically.
Concurrency in Apply to Each
By default, Apply to Each processes items one at a time (sequentially). You can enable concurrency to process multiple items in parallel β up to 50 at a time.
This is useful when the actions inside the loop are independent of each other (like sending emails). It makes the flow run faster but the items may not process in order.
Enable concurrency in the settings of the Apply to Each action.
Do Until
Do until repeats actions until a condition becomes true. Unlike Apply to Each (which loops through a list), Do Until keeps running until you tell it to stop.
Example: waiting for a response
Carlos sends an approval request and needs to check every hour whether the approver has responded. He sets up:
- Do until the approval status equals βCompletedβ
- Action: Wait 1 hour
- Action: Check the approval status
The loop runs repeatedly until the condition is met. To prevent infinite loops, you set a count limit (maximum iterations) and a timeout (maximum duration).
| Loop Type | Iterates Over | Stops When |
|---|---|---|
| Apply to each | A list of items | All items are processed |
| Do until | Nothing specific β just repeats | A condition becomes true (or limits are hit) |
Parallel branches
Parallel branches let you run two or more sets of actions at the same time within a flow.
Example: Carlosβs onboarding
When a new hire is added at Greenleaf Health, Carlos needs to:
- Branch 1: Create an account in the HR system and assign training
- Branch 2: Order equipment and set up the workstation
- Branch 3: Send welcome email and add to Teams channels
These three branches run simultaneously because they do not depend on each other. The flow is faster because it does not wait for Branch 1 to finish before starting Branch 2.
After all parallel branches complete, the flow can continue with a final step β like posting a summary message to the HR channel.
All flow controls at a glance
| Control | Purpose | When to Use |
|---|---|---|
| Condition | If/then/else branching | True or false decisions β two paths |
| Switch | Match a value against multiple cases | Multiple specific values β cleaner than nested conditions |
| Apply to each | Loop through a list of items | Process every item in a collection one by one |
| Do until | Repeat until a condition is met | Wait for something to happen or retry an action |
| Parallel branches | Run actions side by side | Independent tasks that do not depend on each other |
π¬ Video walkthrough
π¬ Video coming soon
Loops and Branching β PL-900 Domain 4
Loops and Branching β PL-900 Domain 4
~9 minFlashcards
Knowledge Check
Carlos has a list of 50 patients and needs to send each one a personalised appointment reminder. Which flow control should he use?
What must you configure on a Do Until loop to prevent it from running forever?
Carlos needs to check a patient rating value and take different actions for ratings of 1, 2, 3, 4, and 5. Which flow control is the BEST choice?
Next up: Time to build a cloud flow from scratch. We will walk through creating instant, automated, and scheduled flows β including using Copilot to describe a flow in plain English.