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
Johan den Ouden17 May 2017

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
Curt Raddatz17 May 2017

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
Johan den Ouden17 May 2017

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
Nuno Maurício18 May 2017

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
Johan den Ouden18 May 2017

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
J.18 May 2017

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
J.18 May 2017

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
Johan den Ouden18 May 2017

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
J.22 May 2017

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
Johan den Ouden22 May 2017

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
Tim Timperman29 May 2017

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
Eric Halim12 Jan (8 days ago)

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.