Skip to main content
ashutoshg0001
October 8, 2021
Question

How can i display a statement only once in a loop which is running 4 times?

  • October 8, 2021
  • 4 replies
  • 1 view

Hi,

     I have the following code where i want to display the message "Hello World" only once in a loop . what condition i should write?


a!localVariables(

a!forEach(
                   items: {1,2,3,4},
                  expression:
                    {

                                   concat("Hello "," World")

                    }

              )
)

    4 replies

    dastagirid756
    October 8, 2021

    In order to display a message once in a loop, first decide the condition for displaying a message. Then implement the condition inside the loop.

    For example, if I want to display the Hello World when I reach second iteration or item, follow the below code snippet

    a!forEach(
    items: { 1, 2, 3, 4 },
    expression: {
    if(
    fv!item = 2,
    concat("Hello ", " World"),
    null
    )
    }
    )

    To avoid null values in the results:

    reject(
    fn!isnull,
    a!forEach(
    items: { 1, 2, 3, 4 },
    expression: {
    if(
    fv!item = 2,
    concat("Hello ", " World"),
    null
    )
    }
    )
    )

    ashutoshg0001
    October 8, 2021

    Thank you

    acaciob0002
    October 8, 2021

    Hi there,

    I'm not sure if I got your requirement, but if you just want the unique values after a loop, you can try something similar to that:

    a!localVariables(
      local!a: a!forEach(
        items: { 1, 2, 3, 4 },
        expression: { concat("Hello ", " World") }
      ),
      union(local!a, local!a)
    )

    Regards,

    Acacio B

    ashutoshg0001
    October 8, 2021

    Thanks it works