How to escape from inner loop to outer

Hi guys.
I have the following sequence:

for each{
for each{
for each{
if a=b{… }
}
}
}
I need to do smth instead of … to escape from two inner loops in order to iterate furher by outer loop.
Smth like break maybe…
Any ideas?

1 Like

Hi @Slavich,
Have you tried using while and/or do while?

Use the break activity. This will break out of the innermost for each loop it is currently iterating through.

@Dave ,
Is it possible to break simultaneously from 2 inner loops?

@Slavich, one break will take you out of first inner loop only… for another you need to put break again.

The condition be like
This

for each
{
for each
{
for each
{
if (a=b)
Then
{… }
Break;
Else
{… }
Break; // if needed
}
Break;
}
}

Simple isn’t it
Cheers @Slavich

Thank you, @Palaniyappan.
Is there an option, besides, to check - if inner loop got break, then break from outer. ?

1 Like

Yah of course
In the third for each loop in the THEN part before to break activity use a assign activity like this
Out_bool = True
—so now in the second for each loop next to its inner for each loop (third loop) use a if condition like this
Out_bool = True
If the condition passes it means it will go to the THEN part where we can use a break activity so that only when there is a break in third for each loop this break will occur
— but make sure that we make a assign activity like
Out_bool = False
As a first activity In The second for each loop

Like this
for each
{
for each
{
Out_bool = False;

for each
{
if (a=b)
Then
{… }
Out_bool = True;
Break;
Else
{… }
Out_bool = True;
Break; // if needed
} \third for each loop ends

If (Out_bool = True)
Then {
Break;
}
Else
{
}

} \second for each ends
} \first for each ends

Hope this would help you
Cheers @Slavich

Got it!
Thanks a lot, @Palaniyappan

1 Like

Cheers @Slavich

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