Exit Loop before entire list is looped through

Hi! It would be great if we could exit a loop in a function before the entire loop is completed.

Use case: Looping through a list of items where only 1 action needs to be completed, but not sure on which one, once that first one is hit I want to exit the loop so to not need to loop through every item.

@OlgaStroilova @amit.malik for vis.

Thank you Simon! Breaking out of loops and similar control logic is also on the backlog. Thanks for upvoting.

1 Like

Simon do you mean with the looper widget?

I’m pretty sure we do this already with Step Looping, just would need to have a clause in your trigger that would cause a transition away from the looping step once you get to the list element that corresponds to the required action - depending on what that is, it could be detectable during the iteration that acts on that list element, if not, it could be on the subsequent iteration.

Hi Jim! I do not mean the looper widget, I mean Functions Looping.

Cheers!

As a workaround you can put everything you want to do in the loop into a decision. If your exit contition is met, the loop will run empty:

With an expression Condition | @variables.exit you can keep the exit if once set.