Looping options in Azure Logic Apps
With Logic Apps you have several options regarding looping in your workflow definition. Logic Apps supports do-while and for-each looping. For instance, you can interact with arrays by going through each element using a for-each loop, or you can instantiate a separate flow (Logic App) for each element using the Split-On command. With the for-each loop, you can choose between running it sequential or in parallel.
Assume you have a news RSS-feed you like to consume every day and each feed contains one or more news items. You loop through the news items with the for-each control action in a Logic App. When configuring the for each, you can set the concurrency control to 1 up to 50 degrees of parallelism. With one degree of parallelism, you run the for-each sequentially (see also Logic App tip -Improve Performance Using Parallelism).
When you do need to iterate through all the elements within an array whether you execute them in parallel (by default) or sequential a for-each is a good fit. Or when you need more isolation and do not need to aggregate results, or require faster execution you could use a child Logic App with the Split-On command. Below you’ll find a table describing the difference between a for each action and calling a child Logic App with Split-On.
|For-each action||Call child Logic App with Split-On|
|Run multiple iterations in parallel (50 max)||No upper limit on how many child Logic Apps can run in parallel after the split|
|Wait for all iterations to complete||Parent Logic App fire-and-forget|
|Aggregate results from all iterations to determine the for-each status||No aggregation in parent Logic App|
Lastly, there is a blog post by Toon VanHoutte about Working with collections in Logic Apps that provide you with extra details about handling arrays.
Depending on your requirements you have a few options when it comes down to looping inside Logic Apps.