Exiting while loop by "Continue" to go to "For Each" activity


I’ve been using “While Loop” activity in UipathTeam.Core.Activities package to be able to put “Break” within the while loop (I have “If” activity inside the while loop, I want to break at the end in then scenario and continue at the end in else). My while loop is inside a for each. Before this, within the “While” activity, I could easily put “continue” in the else section and it would go back to the beginning of for each. Now, with this “While Loop”, I could add the “While Break” activity, but when it comes to “Continue”, it goes back to the while loop and it stays in the loop. How can I continue and go back to for each? Could you please help, or guide to the right place? Thanks in advance.


To go back to the For Each loop, you need to use Break. Break exits the current loop you’re in and resumes execution at the end of that loop. Continue starts at the beginning of your current loop.

Also, generally speaking, there is a school of thought around not using Continue and Break where reasonable. The reason is that you can more easily determine the exit conditions of your loops if they are defined in one place in the code. However, this is not a hard rule, and there are cases where using Break and Continue can make the code more readable. I’m just advising that you use them with caution. :slightly_smiling_face:

1 Like

welcome to uipath community
if i m write your workflow is like this

–For each

now usually we will be having a condition like WHILE loop and only if that condition passes it will cycle again within while loop
and as we have used IF activity inside the while loop and atlast in the THEN part of IF condition use a assign activity like this
bool_exit = True

–so we should have set the condition in while loop like this
your current condition AND bool_exit = False

and before to the WHILE loop use a assign activity like this
bool_exit = False

so the sequence will be like this

assign activity with bool_exit = False
WHILE loop with condition AND bool_exit = False
inside the THEN part at last use a assign activity like this bool_exit = True

so once after the IF condition it will go to WHILE loop again and the condition will fail as the boolean is now set to True value
and it will go to FOR EACH loop for next item

Cheers @bunyaminaydin


Thank you for your reply! :slight_smile:


It feels great to join the community. Thank you very much for the reply, I used Boolean expressions instead of trying to use the “Continue” activity, and created conditions to exit each loop. It is now solved, thank you @Palaniyappan.


Cheers @bunyaminaydin

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.