Use loops
Loops are a fundamental concept in desktop flow development and prove to be invaluable elements in complex flows. The main idea behind a loop is to make a desktop flow repeat one or more actions multiple times.
Power Automate provides three different kinds of loops that iterate based on various factors:
- Simple loops - Iterate for a set number of times
- Loops condition - Iterate as long as a condition is valid
- For each loops - Iterate through a list
Simple loops
The idea behind a loop is to make a desktop flow repeat one or more actions multiple times. Power Automate implements the simplest type of loops with the Loop action.
This loop repeats the actions between the Loop and End actions for a set number of times. A loop index variable is created automatically to track the current iteration’s number.
A simple loop is ideal to use in two cases:
The exact number of times that a block of actions should be repeated is known.
The loop index variable must be used somewhere inside the loop.
In case you need to exit the loop before the specified iterations are completed, use the Exit loop action. To skip the current iteration, use the Next loop action.
Loop condition
Unlike simple loops, the Loop condition makes a desktop flow repeat one or more actions as long as a condition is true.
If the condition is always true, the loop will never end. This situation is called an endless loop.
The condition consists of two operands and an operator. The platform supports the most significant logical operations, such as equal, not equal, and greater than.
In case you need to exit the loop before the specified iterations are completed, use the Exit loop action. To skip the current iteration, use the Next loop action.
For each loop
The For each loop iterates through a list (or data table) and stores the current item in a variable. Its primary purpose is to get each item of a list (or row of a data table) and use it in other actions.
You can use this kind of loop to search for specific names, contents, or attributes in all kinds of lists. For example, you can iterate through a list of retrieved files to find a file with a specific name.
In case you need to exit the loop before the specified iterations are completed, use the Exit loop action. To skip the current iteration, use the Next loop action.
You'll find the list of loop actions available in the Actions reference.