Skip to main content
jalajv3083
October 10, 2022
Question

Implement Break Statement in the appian

  • October 10, 2022
  • 4 replies
  • 0 views

Is there any method to getting out of the forEach() like any break loop method?

    4 replies

    harshitb6843
    October 10, 2022

    Nope. You can add an if condition in the a!forEach() and where you want to add a break, you can start putting null instead. 
    And in the end, you can reject all the null values. 
    -UPDATE-
    Adding the code block below. 

    reject(
      a!isNullOrEmpty(_),
      a!forEach(
        items: enumerate(10),
        expression: if(fv!item < 5, fv!item, null)
      )
    )

    mikes0011
    Brainy
    October 10, 2022

    instead of null, have it output empty set ({}).  These will disappear from the output array (unless all results are an empty set - if this corner case is possible just wrap the a!forEach() in a!flatten() and the list of empty sets will be collapsed to an empty set).

    The Expression Guru
    harshitb6843
    October 10, 2022

    Wow. Didn't know that. Thanks, Mike!

    stefanhelzle0001
    Brainy
    October 10, 2022

    What kind of logic do you want to implement that you need a break for? In case you are looking for something more complex, check out my blog post: https://appian.rocks/2022/08/29/complex-algorithms-in-appian/