How to stop first for each loop in using nested for each loops by using break

Scenario:Using nested loop when i met my expected condition the first loop will Stop or End

Steps to reproduce: 1) Create a first for each loop

  1. Create second for each loop in First for each loop
  2. Create If Condition and if true then use break

Current Behavior: stop the second for each loop and executing the first loop

Expected Behavior: stop the Entire loop when my condition met

Studio/Robot/Orchestrator Version: community version

Last stable behavior:
Last stable version:
OS Version:
Others if Relevant: (workflow, logs, .net version, service pack, etc):

Hey @mytest1724_1724

There is no way of using break to break out of multiple loops. The break command will always just apply to the inner most loop.

You can do like this

Bool break_flag = False;

                  if(your condition ==true)
                    break_flag = true;
    if(break_flag== true)



Thank You aksh1yadav

I have issue breaking the first loop in a nested loop scenario. UIPath is not moving to next line of code after breaking of first loop and just get into wait.

loop 1
line of code
line of code
loop 2
line of code
loop2 exception handler
end loop2
exception handler loop1
break; comment: it is coming to this line of code but not breaking and moving to ‘more line of code’
end loop1.
more lines of code.

This issue is under development, i don t have a timeframe for now.

Hi Venkat_Vuyyuru:

You can stop the first for each loop using an if statement after.

For example, if you arrive to the last part of your inner loop, you can assign a boolean variable a value of “True” (or "false if you want), so when the first for starts again, in the other part of the first if statement you put a “break”.

I hope to have been clear.


Is there any possibility to remember the values when it comes out of the loop. I am automating through multiple folder within a subfolder so and checking subfolder consists files or not. If it consists then it has to do processing. Here I am using loop. So, when it done processing the file and go back to its loop the fileindex variable is getting 0. Please suggest on the same

Hi @ushu, can you post a copy of the xml so we can see how you’re doing it currently?

Hi, i am using two for-each loop i want first for-each loop get value1 and second for-each loop get value1 after getting value1 from 2nd for-each it has to return to 1st for-each loop for value2 .I have given my screenshot and myproject given below .

InvoiceDemo (2).zip (268.7 KB)