cancel
Showing results for 
Search instead for 
Did you mean: 

Exit ForEach loop with condition (like in a WHILE statement)

filipe-oliveira
Deputy Chef I
Deputy Chef I

Hello Workato Community,


Is there a way to exit a ForEach loop given a specifc condition (like in a WHILE statement)?


I'm just looking for an ID in a list and I want to stop the ForEach once the ID is found.

I added an IF condition inside the ForEach but, as per my understanding, this would just prevent the following steps inside the ForEach from being executed, but the ForEach would still need to iterate through the whole list.




Thank you,

Filipe

9 REPLIES 9

vinny-sosa
Deputy Chef I
Deputy Chef I

This is the only way that I am aware of the do it. I know it seems like a waste of cycles but the iteration happens pretty quickly. This feature is much much needed and long overdue.

Vinny and I just discussed this recently. You can submit product feedback on this.

ajorde
Deputy Chef I
Deputy Chef I

You could call a function to iterate on the loop and then return response/stop job from the function when it meets the criteria. You would still need a list to iterate through in the function.

mike-flynn1
Deputy Chef II
Deputy Chef II

sometimes the .where function can help prevent unnecessary loops.


I also echo Vinny, as an engineer I hate wasting electrons but a simple if statement also gets the job done. I have tried many different ways of breaking a loop in Workato and it didn't work out well - so now I just keep it simple.