In a Do Until loop, with a condition (such as a certain variable is greater than 1), at what point does the do Until loop stop? Does it stop at the beginning of the iteration when the condition is met (and thus does not implement actions below it once the condition is met) or does it see that the condition is met, run the loop once more, and then quit?
Solved! Go to Solution.
In my experience it evaluates the condition at the top of the loop. So if the condition is true when you enter the loop it will never execute the actions inside the loop.
In my experience it evaluates the condition at the top of the loop. So if the condition is true when you enter the loop it will never execute the actions inside the loop.
It should do the actions once and then move on
Do (run the actions) then Until (check the condition)
Thanks for that answer, very helpful. One other question. Will a Do Until work properly if it is embedded inside an Apply to Each loop? In my case, I am checking a condition to see if it is true, but I need an apply to each loop for to check each record in a SharePoint list. I'm not sure if Do Until works properly inside a loop. See screenshot. "Loop daily list" is an apply to each loop that gets records (items) from a SharePoint list, then uses an item from that list in the do until comparison. I am trying to get the list loop to exit once the condition is met, to avoid unnecessary repetitions.
my post below did not seem to keep the screenshot. Trying again.
From my testing, I have not found a way to exit a loop before all items in the Apply to Each loop are completed. I tried using a Do Until loop with a condition, but as soon as the condition involves multiple items from a SharePoint list, an Apply to Each loop is added, and that loop will not exit until all items have been checked.
My conclusion is that loops which involve checking multiple items in a list or library cannot be exited early based on conditions. We really need a "break" function.
If anyone has figured out a way to exit a loop (where repeating items are involved), please let the community know.
Honestly cannot believe that a "break" hasn't been implemented.
Do until will work fine inside an Apply to Each, but breaking out of the Do Until will just run the next apply to each loop. There is no way to break out of an apply to each loop without terminating the entire flow.
Which is preposterous.
Why is that preposterous? Its apply to each, not apply to them until I decide differently. You can easily replace the Apply to each with a do until loop and get the ability to break out of the loop. Just because doesn't work the way you want it to doesn't make it wrong or preposterous.
Apologies - I shouldn't have said that yesterday. 😔 I find the user interface very frustrating to use and my temper got the better of me.
I was concerned that using a do until would be inelegant if the condition is never satisfied but I know that we can limit the number of executions. I will try this.
I have experienced the opposite, where the loop will run regardless of the conditions being met in actions prior.
I tested this by setting up a manual flow that has a Do Until loop with the condition to not run if the variable is greater than 0. I initialized the variable at 1 and ran the flow and the action inside the loop still ran. See attached image as evidence.
This suggests that Do Until actions check the conditions after their first run, rather than at the start.
The easiest way around this would be to put the loop inside a condition matching that stated in the loop conditions. This is a bit redundant but seems necessary.
However, this has proven troublesome in some of my more complex flows where I hit the nesting limit when doing this. In response, the solution I have adopted is to utilize run conditions in actions prior to the Do Until loop. For example, by putting that matching condition action before the do until loop and forcing a failure in the "Yes" box the actions below will be skipped. The way I have been forcing a failure is using the expression formatDateTime(null), but any other should do. You would then need to add a parallel branch that runs on action failure. Finally, the action after the scope containing all this would need to run on both success and failure of the scope. See image below.
Admittedly, this solution is convoluted, to say the least, and it makes error handling a bit tricky because unless you specifically address it any errors that happen inside this scope would be ignored and the flow would continue. So I am open to hearing any other workarounds that people smarter than myself may have come up with.
The Do Until action always executes the loop at least once, it appears. The Accepted Solution here should be changed.
Do until loop does not stop checking the condition even though the condition is met. It keeps on checking the condition until it runs out of time out or count. It weird that it won't stop once the condition is met.
It ran for 5 times within 5 minutes (i kept time-out value of 5min).
User | Count |
---|---|
89 | |
37 | |
26 | |
13 | |
13 |
User | Count |
---|---|
127 | |
54 | |
38 | |
24 | |
21 |