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

uiautomation

#1

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):


#2

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;

foreach{
    foreach{
                  if(your condition ==true)
                  {
                    break_flag = true;
                    break;
                  }
              }
    if(break_flag== true)
    {
      break;
    }
}

Regards…!!
Aksh


#3

Thank You aksh1yadav


#4

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.

ex:
loop 1
line of code
line of code
loop 2
line of code
loop2 exception handler
break
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.


#5

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


#6

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.