Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 38 ยท Approvals and Control Flow

Do Until, Scope, Parallel Branches and Terminate

Control the shape of a run: Do until loops with count and timeout limits, Scope to group actions, parallel branches, Delay, and the Terminate action with Succeeded, Failed and Cancelled.

Conditions choose a path and Apply to each repeats work per item. Four more tools complete the control-flow toolbox: Do until (repeat until something becomes true), Scope (group actions into one unit), parallel branches (do independent things at the same time) and Terminate (end the run on purpose with a chosen status).

This lesson explains each, with the limits you must know. The designer cannot run here, so the examples are JavaScript stand-ins that model the logic.

Do until

Do until runs its actions, then checks a condition; if the condition is not yet true it runs the actions again. Notice the order: the actions run at least once, and the test happens after each round.

Typical uses: poll a service until a job reports Completed, wait until a file appears, retry something a bounded number of times.

flowchart TB
    S["Start"] --> A["Check status of job"]
    A --> C{"Status is Completed<br/>or limit reached?"}
    C -->|"No"| W["Delay 30 seconds"] --> A
    C -->|"Yes"| E["Continue the flow"]

The loop ends when the condition is true or when a limit is hit, whichever comes first.

The two limits

Open Change limits on the Do until card. Two settings stop a runaway loop:

  • Count: the maximum number of iterations. The default is 60.
  • Timeout: the maximum total time as an ISO 8601 duration. The default is PT1H (one hour).

When either limit is reached the loop ends without an error, even though the condition is still false. That is a common bug: the flow carries on as if the job had finished. Always test the condition again after the loop (for example check the status variable) and handle the "gave up" case.

Put a Delay inside the loop so you are not hammering a service. A loop with no delay can use all its iterations in seconds.

JS Stand-in: Do until with count and timeout

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Delay and Delay until

The Schedule connector offers two actions that fit control flow:

  • Delay: wait a fixed amount (a count and a unit such as minutes).
  • Delay until: wait until a timestamp in ISO 8601 form, for example a due date from the trigger.

While a flow waits it consumes no compute, but it still counts toward the maximum run duration of 30 days. For longer timers, store a date and use a scheduled flow instead.

Scope: grouping actions

A Scope is a container. You drag actions into it, collapse it, and rename it ("Create the records"). Two benefits make scopes central to good flows:

  1. Readability. A long flow becomes a short list of named blocks.
  2. One status for many actions. A scope succeeds only if everything inside succeeded; it fails if anything inside failed. You can configure the next action to run after the whole scope fails or times out, which is the basis of try/catch handling in the run-after lesson.

Scopes can be nested, and conditions or loops inside them behave as usual. Variables initialized at the top level remain visible inside scopes.

Parallel branches

To run independent work at the same time, hover over the arrow between two actions and choose Add a parallel branch. Each branch runs on its own; the first action after the branches runs only when all branches finish.

flowchart LR
    T["Trigger"] --> A["Send email"]
    T --> B["Create ticket"]
    T --> C["Post to Teams"]
    A --> J["Next action<br/>waits for all three"]
    B --> J
    C --> J

Parallel branches shorten the run when actions do not depend on each other.

Take care with two points. First, branches must not depend on each other's output. Second, the same trap as concurrent loops applies: do not change one shared variable from several branches. Use separate variables or combine results afterwards.

JS Stand-in: sequential versus parallel time

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Terminate

The Terminate action (Control connector) ends the run immediately. You pick a Status:

Status Meaning Extra fields
Succeeded End now and mark the run successful. None
Failed End now and mark the run failed. A Code and a Message you choose
Cancelled End now and mark the run cancelled. None

Use Terminate for early exit ("if the input is invalid, stop"), which avoids deep nesting: test, and if the test fails, Terminate with Failed and a clear message instead of wrapping the rest of the flow in an If yes branch. It is also how you make a flow report failure after you handled an error yourself; without it, a flow that caught an error and carried on will show as Succeeded.

A Terminate with Failed inside a branch ends the whole run, not just the branch, and the other branches stop too. Put it only where that is what you want.

Choosing the right tool

Need Use
Choose one of two paths Condition
Choose one of many exact values Switch
Repeat per item Apply to each
Repeat until something is true Do until, with Count, Timeout and a Delay
Group and report one status Scope
Run independent work together Parallel branches
Stop early or force a failed run Terminate

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A Do until loop reaches its Count limit while the condition is still false. What happens?

    Limits end the loop silently, so test the result again after the loop.
  2. 2. When does Do until check its condition?

    It is a do-while style loop.
  3. 3. What does a Scope give you besides tidiness?

    A scope fails if any action inside fails, and later actions can react to that.
  4. 4. A flow catches an error with run-after and sends an alert, but should still show as failed. What do you add?

    Terminate with Failed marks the run failed on purpose.

Summary

  • Do until repeats until its condition is true; set Count and Timeout, add a Delay, and check the result after the loop because hitting a limit is not an error.
  • Scope groups actions and reports one status.
  • Parallel branches run independent actions together; the next step waits for all.
  • Terminate ends the run with Succeeded, Failed (code and message) or Cancelled, and is the tidy way to exit early.

Next: Power Automate Desktop and Desktop Flows