Can we exit from a!forEach() loop?

Certified Senior 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