how to break a for-each loop if exception is found?
I currently have a collection of dates, and I added a for-each loop to go through each date and check if the status in that date matches the current status (using the if/else activity). How would I break the loop if an exception is found, i.e. the status in the date does not match the current status, and follow a different flow (exception work flow)? I don’t want it to continue to the next date in the collection if the exception is found.
we can use BREAK activity in any of the part either THEN or ELSE based on your condition where you want to stop when it enters into any of the part
or we can use CONTINUE activty along the if/else condition
we got an example as well here
I added a break activity, but it keeps going back into the foreach loop for the next item. I want to break it the loop so it doesn’t go to the next time and check. After it breaks the loop, i want it to follow a different work flow (invoke exception workfile). How would i do this?
I added a message box after the break that say “this should break here”. When i run it, and it reaches an exception, it proceeds with that message “this should break here”, but right after that, it just goes to the next item in the collection.
Assign breakLoop = false
Assign x =0
While x <= dateArray.Length And breakLoop = false
Assign d = dataArray(x)
if d = your condition then
' do whatever it is with the date ...
Assign x = x + 1
I tried it with the while loop and for loop. I think it does have something to do with while-loop. It keeps looping. I think i am not approaching this right. Would you be able to show me how to break the for-loop inside of a while-loop?
After breaking the For loop, do you also want to get out of the While loop? If so, are you ensuring that condition is met before breaking the for loop?
If you haven’t already done so, you should use the debug mode in your workflow and step through it one action at a time. Be sure to be looking at each variable/argument value to ensure it is what you’re expecting. This should help narrow down why it is acting weird in your workflow. Since it’s working in a newly created simple workflow it means that it has to do with the logic created in your actual workflow