Is there a way to "break" a for loop?

Hello,
I would like to know if it is possible to have some kind of option to “stop” looping through a for loop, whenever some condition is met.

The idea is to:

=> Perform an action ONCE, whenever a condition is met. The problem is that I can’t know if this condition will be met once, twice or many times while looping through a for loop.

Solution A: What would be optimal would be to have a variable (boolean) that takes the “true” value whenever the condition is met. Then at the end of the loop, the value is verified and an action is performed.
But Let variables cannot change their values in aql.

Solution B: Instead the for loop should stop looping whenever the condition is met, and then an action can be performed, once.

If none of the 2 options mentioned above are possible then my action would be performed a X unknown number of times through my for loop. Which can be a problem.

Unless there is some other third option to realize this? I wonder. Thanks

You probably need to use an if statement with the any() service:

{m:if expression->any(e | e.condition) <> null}

The then block will be generated if at least one element match the condition.

I am note quite sure how to implement the any() service here, let’s take this example:

The first number greater than the test value is:

m:let Test=‘45’
m:let XX= Sequence{1,2,3,4,59,61,100}
m:if XX…
m:for X|XX
m:if X > Text.toInteger()
The first number greater than the test value is: {m: X}
m:endif
m:endfor
m:endif
m:endlet
m:endlet

It could not be “m:if XX->any(e|e.>Text.toInteger() <> null”. How could this be translated properly?

Remined: I would like to test the condition through my sequence until is it met ONCE, then the FOR condition should stop.
So the result should be:

The first number greater than the test value is: 59

And not : "

The first number greater than the test value is: 59
The first number greater than the test value is: 61
The first number greater than the test value is: 100

"

You can use:

 The first number greater than the test value is: {m:XX.any(X | X > Text.toInteger())}

Thank you.
It’s strange, there is an error message about the any service not being found. I tried to simplify it fully in order to debug it, i removed the ToSring function and kept only an integer type variable.

m:let var=45
m:let XX= Sequence{1,2,3,4,59,61,100}

The first number greater than the test value is: {m:XX.any(X | X > var)}

m:endlet
m:endlet

Result:

m: XX.any(X|X> var <—Couldn’t find the ‘any(java.lang.Integer,Lambda(java.lang.Integer, ja-va.lang.Boolean))’ service)

My bad:

The first number greater than the test value is: {m:XX->any(X | X > var)}
1 Like

I should have seen it.
Thank you a have a good end of week.