Do Until (loop until a condition is true)
Automate with Precision: Mastering the ‘Do Until’ Loop in Power Automate
Primary Keyword: do until Power Automate
Secondary Keywords: Power Automate loops, repeat actions, loop until condition true, exit condition Power Automate
Table of Contents
- Introduction to Looping in Power Automate
- What Is the “Do Until” Loop?
- Why Use “Do Until” Instead of “Apply to Each”?
- Core Components of the “Do Until” Control
- How to Set Up a “Do Until” Loop
- Understanding Loop Exit Conditions
- Real-World Use Cases of “Do Until”
- Expressions and Variables in Do Until
- Using Delay Actions to Control Loop Timing
- Performance Considerations and Loop Limits
- Common Mistakes to Avoid
- Best Practices for “Do Until” Logic
- Final Thoughts
1. Introduction to Looping in Power Automate
Power Automate provides several loop mechanisms to help you repeat actions when working with lists or time-dependent events. While the “Apply to Each” loop is used to iterate over collections, the “Do Until” control allows you to loop until a condition becomes true — a powerful technique for automating wait-and-check, retry, or status-monitoring scenarios.
If you need to repeatedly perform actions until something changes, the “Do Until” control is your best friend.
2. What Is the “Do Until” Loop?
The “Do Until” loop in Power Automate is a control that keeps executing the steps inside it until the exit condition is met.
It’s perfect for:
- Waiting for approvals
- Checking API response statuses
- Monitoring data for changes
- Implementing retry logic
The loop:
- Starts with an initial action
- Repeats a block of actions
- Exits when the specified condition evaluates to true
3. Why Use “Do Until” Instead of “Apply to Each”?
Feature | Do Until | Apply to Each |
---|---|---|
Purpose | Repeat until condition | Loop through collections |
Exit Condition | Boolean expression | End of array |
Use Case | Wait for status change | Process list of items |
Control Mechanism | Condition-based exit | Count-based |
Parallelism | No (sequential only) | Optional |
Choose Do Until when:
- You don’t know how many times the loop will run
- You are waiting for a condition to be met
- You’re checking the same variable or field repeatedly
4. Core Components of the “Do Until” Control
Component | Description |
---|---|
Condition | The expression or comparison to end the loop |
Loop Body | Actions executed in each loop iteration |
Timeout/Count Limit | Optional: Prevent infinite loops |
Delay | Optional: Pause between iterations |
The loop stops when the condition is true or when it reaches the maximum number of iterations or timeout period, whichever comes first.
5. How to Set Up a “Do Until” Loop
Basic Setup:
- Add a “Do Until” action.
- Define the exit condition (e.g.,
Status equals Approved
). - Add actions inside the loop — these will execute each time.
- Optionally:
- Set the timeout (e.g., 1 hour)
- Limit the number of iterations
- Add a Delay action for time-based checks
Example: Wait for SharePoint Approval
Goal: Check every 5 minutes if a SharePoint item’s status becomes “Approved”.
Steps:
- Inside Do Until:
- Get SharePoint item
- Condition:
Status = 'Approved'
- If not approved: wait 5 minutes
- Repeat
This flow keeps polling until the status becomes “Approved” — then it proceeds.
6. Understanding Loop Exit Conditions
The exit condition is a logical expression that should return true to stop the loop.
Common Operators:
equals()
greater()
less()
not()
and()
,or()
Sample Expressions:
equals(outputs('Get_item')?['body/Status'], 'Approved')
greater(variables('Retries'), 5)
Pro Tip:
Always ensure the field you’re evaluating exists and is populated before using it in a condition.
7. Real-World Use Cases of “Do Until”
⏳ Use Case 1: Wait for Document Approval
- Trigger: Document uploaded
- Action: Start approval
- Do Until: Status = “Approved”
- Loop: Check status every 10 minutes
🧠 Use Case 2: Retry an API Until Success
- Trigger: Flow starts
- Do Until: Response code = 200
- Inside Loop: Send HTTP request + Delay 1 min
📦 Use Case 3: Monitor Inventory Status
- Trigger: Item stock = 0
- Do Until: Stock count > 0
- Loop: Check every hour and send alert when restocked
🕹 Use Case 4: Check When Power BI Dataset Refresh Completes
- Trigger: Dataset refresh starts
- Do Until: Status = “Completed”
- Loop: API call every 5 minutes
8. Expressions and Variables in Do Until
You can use variables to track loop attempts, status, or cumulative values.
Use Case: Retry Counter
- Initialize variable:
Retries = 0
- Inside loop:
- Increment
Retries
by 1 - If retries > 5 → Terminate flow
- Increment
Sample Expression:
less(variables('Retries'), 5)
This approach adds intelligent control over how many attempts you make.
9. Using Delay Actions to Control Loop Timing
Without a Delay, the loop executes almost instantly, which can lead to:
- API throttling
- Rate limits
- Unnecessary resource usage
Solution:
Add a “Delay” action inside the loop to pause between iterations.
Example:
Delay: 5 minutes
Use for polling scenarios where you check something periodically, like status changes or external APIs.
10. Performance Considerations and Loop Limits
Power Automate imposes limits on Do Until loops to prevent abuse.
Key Limits:
Setting | Default | Max |
---|---|---|
Count | 60 | 5000 |
Timeout | 1 hour | 30 days |
Tips:
- Always configure count and timeout explicitly
- Use Terminate action to gracefully exit on failure
- Use parallel branches cautiously — Do Until loops are sequential
11. Common Mistakes to Avoid
Mistake | Solution |
---|---|
Infinite loop | Set clear exit condition, timeout, or max count |
Forgetting delay | Always include a Delay to avoid rapid-fire looping |
Comparing to wrong data type | Check that fields being compared are of the same type |
Using null values | Use coalesce() or empty() to handle missing data |
Ignoring loop limits | Set Count and Timeout explicitly in production flows |
12. Best Practices for “Do Until” Logic
✅ Define Exit Early
Place your exit condition as high as possible for clarity and efficiency.
🔄 Set Reasonable Count Limits
Avoid default 60 iterations if you need more — adjust to your use case.
⏲ Always Use Delay
5–10 minutes is ideal for most status polling.
💬 Add Logging
Use Append to array or Compose to record each iteration’s result.
🧪 Test Edge Cases
Ensure that the condition eventually evaluates to true — or you’ll hit the limit.
🧩 Combine with Conditions
Use If/Else logic inside Do Until for branching actions per iteration.
13. Final Thoughts
The Do Until control in Power Automate is a flexible, powerful tool when you need to wait, retry, or repeat logic based on dynamic changes. It allows you to implement automation that can adapt to change over time, rather than just reacting once.
When used with expressions, delay controls, and proper exit logic, Do Until empowers you to automate processes like status tracking, long-running workflows, and time-based checks — all with precision.
Frequently Asked Questions (FAQs)
Q1: What happens if the condition never becomes true?
The loop will run until the timeout or count limit is reached. Use both to avoid infinite loops.
Q2: Can I stop the loop manually?
Yes, you can use Terminate or Set Variable + Exit Condition logic to control exit dynamically.
Q3: What’s the difference between Do Until and Apply to Each?
- Do Until: Loop continues until a condition is met.
- Apply to Each: Iterates over items in a list/array.
Q4: Can I nest a Do Until loop?
Yes, but it’s rare. Always consider performance and readability when nesting loops.
Bonus: Sample Use Case Flow Diagram
(Optional graphic: Flowchart showing a trigger → Do Until loop → delay → condition check → exit → next step)
Would you like me to generate a visual diagram or export this as PDF, Word Doc, or Markdown?
I can also prepare your next guide — would you like to cover “Parallel Branching” or “Error Handling in Power Automate” next?