Loop(Power Automate Desktop)

08/23/2023

Japanese version.

Loop is a function that repeats the same process.

Loop Actions

The loop has three actions, which can be used depending on the situation.

ActionDescription
LoopRepeat a specified number of times.
Loop conditionRepeat while specified conditions are met.
For eachRepeat all rows of the List or Data table.

Loop Action

Loop Action repeats a specified number of times.

To use it, drag a Loop Action onto the Workspace.

Set parameters.

Repeat 10 times with Start From set to 1, End to set to 10, and Increment by set to 1.

The Variables produceced (LoopIndex by default) is set to the number of loops.

In the below, the Message box from 1 (Start From) to 10 (End to) are displayed 10 times.

Repeat 10 times, even if Start From is 10, End to is 1, and Increment by is -1.

In this case, the LoopIndex counts down from 10.

This loop is used for count up/down, otherwise the other loops are used.

Loop condition Action

The Loop Condition Action repeats while the specified condition is met.
To use them, drag a "loop condition" onto the Workspace.

Set parameters.

Set a condition similar to If Action. Repeat as long as this condition is True.

For each Action

For each Action repeats all rows of a List or Data table.
To use, drag For each Action to the Workspace.

Specify a List or Data table for Values to iterate.

The Store into (CurrentItem by default) is set to the item at that time.

In the example below, iteration is performed on the list [10,20,30,40,50], and 10,20,30,40,50 will appear in the message box in the display. (5 iterations)

Loop control Actions

There are two actions that can be placed within a loop action to change the Flow of the loop.

ActionDescription
Next loopSkip subsequent actions and move on to the next loop.(Continue)
Exit loopThe subsequent action is skipped and the loop is terminated.(Break)

Basically, it is used when some condition (If or Switch) is satisfied.

For the sake of comparison, we have used a simple example where the condition is LoopIndex=3, but in practice, more complex conditions, such as some kind of error, will be used.

Next loop

Skip subsequent actions and move on to the next loop.(Continue)

To use it, drag the Next loop Action onto the workspace.
The Flow below will display a message box 10 times if there is no Next loop Action, but it will skip only when the LoopIndex is 3, due to the Next loop Action.
The message box will appear 10 times if there is no Next loop Action, but it will be skipped only when the LoopIndex is 3. (Displayed 9 times)

Exit loop

The subsequent action is skipped and the loop is terminated.(Break)

To use, drag Exit Loop Action under Loop.

In the Flow below, the message box would appear 10 times without Exit Loop Action, but the Exit Loop Action displays the message box twice and then exits the loop. The Exit Loop Action displays the message box twice and then terminates the loop.

One way to use the Loop condition Action as a never-ending condition, such as 1=1, and Exit Loop Action as an end condition is to use Exit Loop Action as an end condition.

How to deal with infinite loops

If the loop does not end, the Stop button forces the Flow to stop.

For those who want to learn Power Automate Desktop effectively


The information on this site is now available in an easy-to-read e-book format.

Or Kindle Unlimited (unlimited reading).

You willl discover how to about basic operations.

By the end of this book, you will be equipped with the knowledge you need to use Power Automate Desktop to streamline your workflow.

Links

Power Automate Desktop Introduction.

Examples of Use

Obtain the number, total, average, maximum, and minimum of the numbers in the list.

Send newsletter. Email one line at a time from an Excel book.

How to record the contents of an incoming email line by line in an Excel book.

How to convert URL parameters (GET parameters) into Data table.

How to rank a list of numbers.

How to get the deviation.

How to get the least common multiple and greatest common divisor.

How to get the median.

How to get the standard deviation.

How to get the mode.

Create a table of contents for sheet names in an Excel book.

Delete rows of Excel with specific conditions.

How to delete multiple rows/columns in Excel.

Automated basic text file operations

Specify date range to retrieve mail.

How to save the contents of a PDF to a text file.

How to read an Excel file and process it line by line in a loop.