Can we exit from a!forEach() loop?

Certified Lead Developer

Hi Everyone,

Can we exit from a!forEach() loop? 

I have a use case , where I need to iterate through the list of users and once the condition met ( checking for the user's organization and weight category), I have to stop iterating through the rest of the items. I need order to achieve this, I have to exit from the loop. 

How can I achieve this ?

Apologies for not clarifying the use case earlier.

Use case is given below.

Use Case: There is a list of Boxers. Each boxers belongs to particular organization and weight category. I want to select 2 boxers for the match randomly. 2 boxers must belong to same weight category but different organization.

To achieve this I was trying to loop through list of boxers and fetch 2 boxers belonging to same weight category but different organization. Once I get 2 different boxers, then I wanted to exit the loop, because I got 2 boxers for the match and don't want to loop further. Note: Weight category and organization are not known initially. That also needs to be picked randomly.

Please do let me know if this is still not clear.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hi everyone, 

    this post doesn't provide any resolution to this topic, you can skip it if you want, here is just a bit of my bitter frustration :D 


    Every now and then I find myself returning to this thread.

    Hopefully, one day the miracle will happen, and Appian will include a break or continue in the foreach cycle. Or why not, do...while.

    I can say that we could avoid a lot of unnecessary iteration if we had this, or for someone average like me, to be able to stop the looping simply, without resorting to recursion, sinister strategies or endless trial and error to limit the looping when you need it.... simply and easily (please notice the remarks about SIMPLICITY).

    And I know that some people think “No. There is a reason it is called forEach”, but in other languages, someone (probably smarter/experienced than the average common citizen like me) did not agree and has thought of including the break for the foreach...just saying. 

    Yes, yes, yes, I know, SAIL is declarative and there will be a million reasons to justify why we don't have a simple break in SAIL, but the result is that we don't have it.... and we'll have to deal with it.

    Maybe something Appian could help with is shaping a recipe to deal with this challenge (whisper: hey, if there is any already, post it in this thread and mitigate my ignorance)

    I'll be back here again in a couple of weeks....no doubt.

  • 0
    Certified Lead Developer
    in reply to andresalbertoy0001

    Hm ... what are you missing? I mean, you say that you are missing other looping functions, but what is it that you cannot achieve?

Reply Children
No Data