Add break/continue on cycles

By Filipe Silva on 10 May 2011
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.
J.10 May 2011
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.

Hugo Francisco10 May 2011
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.
J.10 May 2011
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.



Kilian Hekhuis22 Aug 2011
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.
Armando Gomes23 Sep 2015
+1 to this idea.
André Alho25 Jul 2016


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
Justin James26 Jul 2016

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
Pedro Cardoso29 Jul 2016

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
Niels Favreau24 Mar 2016
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
Kilian Hekhuis29 Mar 2016
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
Daniel Cuccia1 Apr 2016
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
Kilian Hekhuis1 Apr 2016
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
enigma27 May 2012
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
J.29 May 2012
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
Kilian Hekhuis22 Jun 2012
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
enigma7 Nov 2012
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
Rajendra koranga13 Feb 2016
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
J.13 Feb 2016
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
J.13 Feb 2016
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
Paulo Sebastião15 Feb 2016
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
Rajendra koranga16 Feb 2016
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