Hello!
I have the following flow on my application:
I want to exit the loop when my variable "TipoDocumentoJaInserido" is set to true. I've already tried the solutions that were suggested on these posts:
https://www.outsystems.com/forums/discussion/22031/is-there-any-way-to-exit-the-for-each-loop-before-the-loop-ends/
https://www.outsystems.com/forums/discussion/8314/breaking-a-foreach-loop/
https://www.outsystems.com/forums/discussion/78053/how-can-i-break-my-foreach-loop/
https://www.outsystems.com/forums/discussion/53065/use-if-to-loop-or-foreach-when-i-might-be-leaving-the-loop-earlier/
But none of them seem work due to my need to append data to the list that is being itered. Is there another way to break the loop?
Hi ViníciusYou can try to put the loop inside a action and there you can break the loop earlier like this:
Then you can use the action in your logic like this:
You can adapt this logic depending on your needs.
Hello.
There are only two ways.
1: create a new action. You can use End in the middle of the ForEach to return to the original.
2: use an ad-hoc loop. Careful with the differences (check here)
Note: I had the idea that we could somehow manipulate the maximum iterations property, but I just tried it and it didn't work so probably I'm confusing tools.
Hi,
You can use ad-hoc loop like below:
1. check LoopIndex (local variable to hold index) with YourListName.List.length and loop until the value of LoopIndex is less than YourListName.List.length.
2. fetch the column value from list using YourListName.List[LoopIndex].ColumnName and check with if condition.
3. if condition "False" then increment index like LoopIndex =LoopIndex +1 and loop continues.
4. if condition "True" then increment index like LoopIndex = YourListName.List.Length to make loop condition false and exit the loop.