cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
martinav
Super User
Super User

How to terminate a Apply to Each loop?

I have to process the name of every folder in a List Files in Folder action.  There will only be one result in this activity.  Thus, when I get a positive to my condition, I need to terminate the loop.  Is there a way to do this?   I would love to be able to use Concurrent, then it would be super fast, but concurrent messes with the results of the condition, so thats a no-go.  Thoughts?

5 REPLIES 5
Mira_Ghaly
Dual Super User
Dual Super User

@martinav

Please check the below article it uses an approach to break out of an apply to each loop. 

https://www.c-sharpcorner.com/article/break-loop-apply-to-each-if-a-condition-fails-in-ms-flow/

 

Hope this helps! 

If this post helps you with your problem, please mark your as Accepted solution.If you like my response, please give it a Thumbs Up.

Blog: here

@Mira_Ghaly ,

 

Well...  it fundamentally does work.  However, the point of it is to save time.  It still takes 32s to run through all 71 items of the loop.  It finishes at item 15, but the remainder where the outside loop is 'false' still takes the same amount of time to execute.  So, there is not much point in it.  

 

This flow is being initiated from a powerapp.  So, I need it to run very fast.  I will have to look at a different way to do this.

sorry .. this is currently a limitation and one of the reasons why many people counsel to steer away from For-Each loops if possible.

 

But without seeing your actual flow I don't see how you couldn't speed this up ... I'm not sure how you are getting filenames but if can pull an array object back Select the Array just to the filename object. then the loop should be really fast.... even with the extra loops.

 

It's been a UserVoice request for a while now.

 

 

AndreyBear
Frequent Visitor
AbdulWahab
Resolver I
Resolver I

Hi @martinav ,

 

I think you can use do-until by using a similar approach. I am in a similar situation after reading the tread I analysed I can solve my problem using do-until. It will help you also.

 

If I have answered your question, please mark your post as Solved.

 

If you like my response, please give it a Thumbs Up.

 

Let me know if I can provide you with more details.

 

Thanks
Regards,

Abdul Wahab
Power Platform & Customer Engagement Developer/Lead/Solution Architecture/Project Manager
Direct/WhatsApp:+923323281237
E-mail: abdulwahabubit@outlook.com
Skype: abdul.wahabubit
Linkedin: https://www.linkedin.com/in/abdul-wahab-a5b8b011a/

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (2,948)