It is impossible to break/continue if you have more then one nested foreach cycle.
Adding an action like a terminator to a cycle could lead to the previous one, for example.
I don't need more local vars!!!
Duplicate of: https://www.outsystems.com/ideas/776/add-break-continue-on-cycles
J.Ja
Although I like it, there's a simple way to achieve it: refactor to an action and exit the foreach with a stop node...
In Out Systems we are not able to come out form for loop until and unless we iterated through whole records in for loop.
When you use a "For each" element it would by very nice to set a breakcondition.
Imagine I have 1000 records and need to find a specific record.
In the loop it would be verhy handy to set a variable IsFound to true and check this on the next interation ofthe loop.
If the records was found on iteration 2 there is no need to iterate the other 998 iterations.
What you are describing is a conditional breakpoint which has been on the idea list for a long time. Here's the link - https://www.outsystems.com/ideas/66/conditional-breakpoint - please like that one.
Oke thanks!
Hi Curt,
I don't think that Johan is talking about that.
He means that we should be able to set a condition in ForEach node that will not keep iterating when that condition match.
The other idea is for debugging purposes. This one is not. This one is for runtime itself.
Am I right?
Cheers.
Nuno,
You are absolulty right!Thanks for your comment and I hope it will be picked up by OutSystems.
there is a similar idea, regarding whiles I believe.
tbh, I don't like the fact you should break out of a for-each loop, because then for-each is not correct naming.
I prefer a new "node" while. :P
https://www.outsystems.com/ideas/1855/while-loop-in-actions
Why not both?
In c# you can also break a in a for each loop.
Hmm,
For some reason I was under the impression, you want to breakout inside the for-each-loop whereever you could.
But if you mean like this:
Yes that is want I meant
The check must be done everytime your on the for eacht widget again
This can actually be achieved by putting the loop inside a separate action, and when your condition is met, you just point to an end node. That way you jump out of the action, and the loop is aborted.
Not usable in all conditions, but it could do the job in specific circumstances.
Yes there are several options to a solution like this. But since it is a common pattern I believe would be better if available in the platform.
In scenarios where we are in a FOR loop, it would be performance friendly to allow us to break out of that loop under certain conditions.
In this example, there are two lists, a list of remote files, and a list of local files. I want to iterate both lists to see if the local file is also in the list of remote files. Optimally, once the file is found, we could break out of the FOR loop without having to check all the other files, however, this code in OutSystems won't compile:
This code WILL compile, but it loops over all remote documents even if the file is found early, you'll notice the only difference is the link from Url to File on the far right of the code graph:
I see no reason, logically, why a programmer couldn't get to the same line of code from two places and it'd be nice if we could do this in OutSystems.
It would be very interesting (for specific cases) if in a For Each when it found the required data, there was a Break action to be able to exit the loop without having to go through a complete list.
Adding the Break Action cancels of For Each interactions and continues the code.
Great Idea!
So for solving this now you can filter the list(LiistFilter action inside Systems default module) with condition you want and will not need to use Foreach widget.
Felt a need for this in before filter was available. Now I think filter can solve almost all of use cases but this feature will be a plus.
+1
This is a valuable idea that as many have mentioned has a possible implementation pattern. We do not have plans to implement this in the foreseeable future. This last statement can be reviewed in the future as always.