DEV Community

Frederik Van Lierde
Frederik Van Lierde

Posted on

For Next Loop in PowerAutomate (Easy)

We all know the 2 types of loops in PowerAutomate
1. Apply to Each:
This is the primary loop mechanism used in Power Automate for iterating over a collection of items, such as arrays.

When you have a list of items and you want to perform certain actions for each item individually, this is the loop you use. Power Automate takes care of the iteration, applying the actions you've defined to each item in the collection.

2. Do Until:
This loop performs actions repeatedly until a specified condition is met.

It's useful when you're not sure how many iterations you'll need, but you have a clear condition that determines when the loop should stop.

This allows for repeating actions based on dynamic conditions that might change with each iteration of the loop.

Available Loop Action in Power Automate

What about For Next Loops?

"For Next"-loops are essential when you need to execute a block of code a specific number of times, especially when you're working with indexes or counters.

They provide a precise control mechanism for iterating through a sequence or range of values.

How to create a For Next Loop in PowerAutomate?

The simple trick is to add as Input for an "Apply to Each" action a Range function

  1. Add a "Apply to Each" action to your flow PowerAutomate ForNext Loop
  2. As Input set "range(0,x)" where x is the number of loops you like to execute PowerAutomate ForNext Loop Range Function

The loop will execute X times.

Top comments (0)