In this tutorial, we’ll discuss how the Do Until loop control works in Power Automate flows. We’ll also get familiar with the needed variables along the process.
The Do Until control in Power Automate is a loop that repeatedly forces an action until a certain condition becomes true.
Creating An Instant Flow
First, let’s create a manually triggered flow. Click Instant – from blank under New.
Then, set the name to “Do Until Example”. Choose Manually trigger a flow and click the Create button.
Let’s add a Text input within the flow.
Then add a Number input.
After that, change the value of the inputs to the following.
Adding A Do Until Loop In Power Automate
Let’s now add an action. Click New step.
Then, click Control.
Choose the Do until control.
Before we execute the Do until function, let’s create a variable.
A variable is simply just a storage space for specified values.
Click the plus icon below the instant flow and click Add an action.
Then, choose Variable under the Built-in connectors.
Click the Initialize variable action.
Let’s initialize a variable called Counter and set its type to Integer. The initial value of the Counter variable should be zero.
Configuring The Do Until Loop Action
For the Do Until loop, we’re going to keep posting the message in Slack until the Counter variable becomes equal to the number that the user types in. So, let’s now add the action.
Search and select the Slack connector.
Choose Post message.
Select budget as the channel to send the message to.
For the Message Text, choose the concat function.
Then, let’s concatenate the message itself with the counter. Under the Dynamic content tab, choose Message.
Add a space and select Counter.
Lastly, click the OK button.
Incrementing The Variable
We need to increment this loop because if we don’t, it will never end. So, let’s add another action.
Select the Variable connector.
Then choose the Increment variable action.
It will require the name of the variable, which is Counter.
And we’ll increment it by one.
Now, we have everything in place. We have a trigger element to initialize a variable. It will then post a message and increment the variable to one. It will continue the cycle until the Counter variable becomes equal to the number that the user has entered.
Testing The Do Until Loop
Let’s test it to see if it works properly. Click Save.
Then click Test.
Select the I’ll perform the trigger action and click Test.
Enter your message and the number of times you want it to be posted. Then click the Run flow button.
Upon seeing the green checkmarks, it’s certain that everything has worked properly.
As we can see, the loop iterated 10 times. For the first loop, we’ll see that the concatenated Counter value within the Message Text is 0. That’s because the initial value that we set for the variable is 0. We can then check the next loop by clicking Next.
For the next loop, we’ll see that the Counter value within the Message Text is 1. That’s because we added an increment after the first loop.
Then, we incremented the second loop again.
Therefore, the Counter for the third loop becomes 2.
The cycle will continue until the condition becomes true. In this case, it will keep going until the counter is equal to 10. And that’s how the Do Until loop works.
If we go to Slack, we should see the ten messages within the #budget channel.
The key thing to note here is we need to make sure we have a way to end our loop. If, for example, we forgot to add the incrementing of the variable, then the flow would totally fail and we would repeatedly get spammed at Slack. The output would look like this.
For instances like this, we’ll need to go back to our actual flow and select the current flow run.
Then just cancel it manually.
This will stop the spamming in our Slack channel.
To conclude, the Do Until loop control allows us to create iterations within Power Automate once a certain condition in our flow becomes true. There are many other scenarios where we can use this control. We can use it to remind someone every 10 minutes to approve something. We can also keep looping through until people stop submitting expense reports.
If we follow the logical approach, we can do wonders and automate many things using this control. Hopefully, you were able to clearly understand how this powerful control works in Microsoft workflows.
All the best,