Having trouble breaking out of a for each loop


I can’t seem to figure out of to break out of a sequence and move onto the next sequence? I’m trying to move from the PRIMARY pin sequence to the Date Verification one. In the PIN sequence I have a for each and inserted a break activity but is doesn’t break it goes back to the top of the sequence and runs again.

Hi

Ensure these points

  1. Column mentioned inside the if condition is correct and is validating with right variable

  2. Change the condition like this

row(“PID”).ToString.Contains(PinNum.ToString)

  1. And are you getting message from the message box kept before break activity

Cheers @jeff.shubzda

1 Like

Break is supposed to quit the current iteration of the loop and go back to the beginning.

What you want to do is put each of the Sequences into a Try Catch. Then you can use Throw to cause it to jump to the Catch block, only skipping the rest of what’s in the Try. For example.

Try Primary PN

  • do Primary PN step 1
  • if something wrong then Throw
  • do Primary PN step 2
    Catch
  • add a System Exception and leave it empty (or do a Log Message or something for informational purposes)

Try Date Verification

  • do DV step 1
  • if something wrong then Throw
  • do DV step 2
    Catch
  • add a System Exception and leave it empty (or do a Log Message or something for informational purposes)

So if you hit that Throw in Try Primary PN it skips to the Catch block (which does nothing). It skips “do Primary PN step 2” and then continues to “Try Date Verification”

Same in Try Date Verification, if you hit that Throw it’ll skip “do DV step 3” and continue with whatever is after the “Try Date Verification” Try Catch

1 Like

@jeff.shubzda

My first guess is that your if statement is never having the then executed. But, if you are noticing that get executed…

Is the for loop in your screenshot a nested loop by any chance?

1 Like

Thank you, I changed the 2 to that code and it still worked, and I do get a message before the break so I’m guessing I have other selects caught up in my loop. As mentioned below. I’m also going to look at trying the other suggestion of using a try catch thanks for all the suggestions!

1 Like

Thank you all for the help, I took all the advice and it now gets me to the process of a no match in the EffDate variable. I know that is does not match. So that tells me it now works. Now to update the date in the else statement.

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