23
 Followers
91
 Likes

Add break/continue on cycles

Debugger
On our radar
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.
Created on 10 May 2011
Comments (37)
It's not very handy to have nested loops anyways, especially if they need to be terminated.

workaround: split them into actions and bubble exceptions.

The idea is to be able to break an inner cicle allowing the user to skip unwanted iterations. That would be awsome when you have several nested foreaches and you need one or more to have break conditions, reducing the number of unnecessary iterations. That would reduce the weight of an action and the time it takes to run, resulting into more optimized actions/methods.
I am not fond of breaking out of for-loops, because for-loops are just made for looping from start to end.
While-loops are conditional-for-loops and are used just for that.

While I understand the problem, I don't think the "break" command is the solution for it. I rather have a while-do-loop and a do-while-loop.



I just have a case where I could really need such a 'break'. I'm looping over a large dataset (made of structures), which contains parent/child dependencies (it's basically a tree). I want to update all childs of a particular parent, but since they're sorted, I can stop once the last one has been reached. A for each is preferable to a hand-constructed while-loop for clarity and not needing to index a record list.
+1 to this idea.


I don't need more local vars!!!



Merged from 'Foreach Break Widget' (idea created on 2016-07-25 14:27:52 by André Alho), on 2016-08-02 10:45:02 by Goncalo Borrega

Duplicate of: http://www.outsystems.com/ideas/776/add-break-continue-on-cycles


J.Ja



Merged from 'Foreach Break Widget' (idea created on 2016-07-25 14:27:52 by André Alho), on 2016-08-02 10:45:02 by Goncalo Borrega

Although I like it, there's a simple way to achieve it: refactor to an action and exit the foreach with a stop node...



Merged from 'Foreach Break Widget' (idea created on 2016-07-25 14:27:52 by André Alho), on 2016-08-02 10:45:02 by Goncalo Borrega
For example, when looping trough a list and a condition is met, we should be able to break out of the loop. (so it doesn't go further)




Merged from 'Breaking out a for each' (idea created on 2016-03-24 13:09:24 by Niels Favreau), on 2016-08-02 10:46:22 by Goncalo Borrega
I'm pretty sure this Idea was posted before a couple of times.

Merged from 'Breaking out a for each' (idea created on 2016-03-24 13:09:24 by Niels Favreau), on 2016-08-02 10:46:22 by Goncalo Borrega
I know its not optimal - but this is how I work around the missing 'break' functionality
(basically re-inventing the "for" operator lol)




Merged from 'Breaking out a for each' (idea created on 2016-03-24 13:09:24 by Niels Favreau), on 2016-08-02 10:46:22 by Goncalo Borrega
Yeah, that works of course. And if you only need to break out the entire action, you could also direct a condition to an End. But it isn't very elegant.

Merged from 'Breaking out a for each' (idea created on 2016-03-24 13:09:24 by Niels Favreau), on 2016-08-02 10:46:22 by Goncalo Borrega

In Out Systems we are not able to come out form for loop until and unless we iterated through whole records in for loop.



Merged from 'Breaking or Coming out from for loop in outsytesms' (idea created on 2017-02-08 07:00:17 by Rocky Raki), on 2017-02-08 12:33:15 by Goncalo Borrega
Merged this idea with 'Exit Loop' (created on 2012-05-27 16:13:10 by enigma)
what about an element, to exit/quit a loop?
instead of looping through thousands of records, where you know they are not going to be needed/used.

Merged from 'Exit Loop' (idea created on 2012-05-27 16:13:10 by enigma), on 2017-08-20 14:11:13 by Justin James
I rather have a while-loop.

Merged from 'Exit Loop' (idea created on 2012-05-27 16:13:10 by enigma), on 2017-08-20 14:11:13 by Justin James
I'm pretty sure this has come up a few times before. Can't bother to search for it right now...

Merged from 'Exit Loop' (idea created on 2012-05-27 16:13:10 by enigma), on 2017-08-20 14:11:13 by Justin James
hey joost, you can do a WHILE loop with an IF =)
one possibility:
- create local variable VAR as integer and set it to 0
- create an IF and set its condition to: "VAR < 0"
- now point the true arrow to any assign/action etc that you want to be done
- and after your assigns/actions return to the IF
- now you only need to add 1 to VAR, for a specific condition, to leave the loop
just be carefull not to endup with an endless loop ;-)

Merged from 'Exit Loop' (idea created on 2012-05-27 16:13:10 by enigma), on 2017-08-20 14:11:13 by Justin James
It would be nice if it was possible to exit from the for each loop without traversing the hole list like .net, i know there is a other way to achive it  like if condition, but why not by for each loop.


Thanks
Rajendra



Merged from 'Exit from for each loop' (idea created on 2016-02-13 05:39:05 by Rajendra koranga), on 2016-10-25 08:30:56 by Goncalo Borrega

Merged from 'Exit Loop' (idea created on 2012-05-27 16:13:10 by enigma), on 2017-08-20 14:11:13 by Justin James
it wouldn't be a for-each loop anymore.



Merged from 'Exit from for each loop' (idea created on 2016-02-13 05:39:05 by Rajendra koranga), on 2016-10-25 08:30:56 by Goncalo Borrega

Merged from 'Exit Loop' (idea created on 2012-05-27 16:13:10 by enigma), on 2017-08-20 14:11:13 by Justin James
oh, and idea already proposed lots of times

Merged from 'Exit from for each loop' (idea created on 2016-02-13 05:39:05 by Rajendra koranga), on 2016-10-25 08:30:56 by Goncalo Borrega

Merged from 'Exit Loop' (idea created on 2012-05-27 16:13:10 by enigma), on 2017-08-20 14:11:13 by Justin James
What about creating a WHILE loop and and a way to iterate over the records in a list ? This would allow doing what is being asked.

Merged from 'Exit from for each loop' (idea created on 2016-02-13 05:39:05 by Rajendra koranga), on 2016-10-25 08:30:56 by Goncalo Borrega

Merged from 'Exit Loop' (idea created on 2012-05-27 16:13:10 by enigma), on 2017-08-20 14:11:13 by Justin James
Hi Paulo, 
                 Yes there is so many obtion, but idea is about to exit from the for each loop without traversing the hole list.

Merged from 'Exit from for each loop' (idea created on 2016-02-13 05:39:05 by Rajendra koranga), on 2016-10-25 08:30:56 by Goncalo Borrega

Merged from 'Exit Loop' (idea created on 2012-05-27 16:13:10 by enigma), on 2017-08-20 14:11:13 by Justin James

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.



Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

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.



Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

Oke thanks!



Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

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.



Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

Nuno,

You are absolulty right!
Thanks for your comment and I hope it will be picked up by OutSystems.



Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

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




Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

http://www.outsystems.com/ideas/1855/while-loop-in-actions



Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

Why not both?


In c# you can also break a in a for each loop.



Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

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:



Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

Yes that is want I meant

The check must be done everytime your on the for eacht widget again



Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

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.



Merged from 'BreakCondition on "For Each" element' (idea created on 2017-05-17 13:11:28 by Johan den Ouden), on 2017-11-10 11:07:45 by Carlos Alfaro

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.

Merged this idea with 'Allow breaking out of FOR loops' (created on 28 Aug 2018 16:47:52 by PJ M)

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.







This comment was:
- originally posted on idea 'Allow breaking out of FOR loops' (created on 28 Aug 2018 by PJ M)
- merged to idea 'Add break/continue on cycles' on 29 Aug 2018 05:25:17 by Johan den Ouden
views
1054
Followers
23