Loop(Power Automate Desktop)
Loop is a function that repeats the same process.
- 1. Loop Actions
- 2. Loop control Actions
- 3. How to deal with infinite loops
- 4. Links
- 4.1. Power Automate Desktop Introduction.
- 4.2. Examples of Use
- 4.2.1. Send newsletter. Email one line at a time from an Excel book.
- 4.2.2. How to record the contents of an incoming email line by line in an Excel book.
- 4.2.3. How to convert URL parameters (GET parameters) into Data table.
- 4.2.4. How to rank a list of numbers.
- 4.2.5. How to get the deviation.
- 4.2.6. How to get the least common multiple and greatest common divisor.
- 4.2.7. How to get the median.
- 4.2.8. How to get the standard deviation.
- 4.2.9. How to get the mode.
- 4.2.10. Create a table of contents for sheet names in an Excel book.
- 4.2.11. Delete rows of Excel with specific conditions.
- 4.2.12. How to delete multiple rows/columns in Excel.
- 4.2.13. Automated basic text file operations
The loop has three actions, which can be used depending on the situation.
|Loop||Repeat a specified number of times.|
|Loop condition||Repeat while specified conditions are met.|
|For each||Repeat all rows of the List or Data table.|
Loop Action repeats a specified number of times.
To use it, drag a Loop Action onto the Workspace.
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 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.
|Next loop||Skip subsequent actions and move on to the next loop.(Continue)|
|Exit loop||The 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.
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)
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.