How to Use the 'Break' Activity in an 'If' Clause to Exit a 'Do While' or 'While' Loop

I have a ‘do while’ loop in which there is an ‘if’ condition that checks if the current time (Now) is greater than a maximum threshold limit. If this condition is met, it will throw an exception. I’m using this construct in various parts of my process. However, I’ve encountered a scenario where I don’t want to use ‘throw’ anymore; instead, I need to ‘break’ out of the loop. Based on my previous research, it seems that ‘break’ can only be used with ‘for each’ loops, and not with ‘do while’ or ‘while’ loops.

Can anyone suggest a way to exit the loop when Now exceeds 5 minutes (stored in the ‘MaxThresholdLimit’ variable)?

Do I need to incorporate the threshold condition within the ‘do while’ loop itself? If so, is the following condition correct?

(not ErrorsToolbarExist and WariningToolBarExist) or Now < ThresholdLimit

In this condition, I’ve reversed the logic from my initial ‘if’ condition, considering that the ‘do while’ loop continues as long as the condition is true. However, I’m still a bit confused. Is this the correct approach, or should it be like this?

(not ErrorsToolbarExist and WariningToolBarExist) or Now > ThresholdLimit

That was true with earlier versions, however after some update it works with “While” type of loops as well.

as of my current version is not supporting it , so i have to use diffrent method

May I know which version of UiPath.System.Activities you are using?

its version at 23.8.0 for System.Activities

Then you should have no trouble using a Break.

You can even test in a simple way. Create a new sequence just containing these activities
image

image

Alright, that’s interesting :thinking: What Studio version are you using? And can you check if upgrading the UiPath.System.Activities helps, as I see you are using a preview version?

No i dont want to upgrade it , i dont want to mess things up right no , if upgrading causse any problems with my already existing activties in place, i dont have the time to rebuild the process , is there any other solution , as shown in the question above

The version for UiPath studio currently im using is 2023.8.0

You can always downgrade if you get problems. But it’s always better to avoid using alpha (preview) version of packages.

no im sorry i cant take the risk right now, yes i knew it wont affect , but its still better to be on safe side as the process is completed 99 %

we understood so far but would also recommend for the next projects not to use preview packages.

From your above screenshot, we have some doubts on the surrounding parts

we can rewrite (as same we did in older days) and will take control within the loop condition. Using variable for the loop condition did help for the implementation

1 Like

Hi,

Is your DoWhile activity InteruptibleDoWhile? Please check it at the Property panel.

image

If not, try use this.

Regards,

If you don’t want to change package versions (there should be little risk though, if you just backup your project) there is an alternative:
In your do while loop, just create the condition b_Complete = false and in your if-validation set b_Complete = true
Depending on your actual process this might require a little bit of nesting of if/else blocks, if after where you’d normally place a break would be a lot of executing code, but it is at least an option to bypass the bug in the break activity.

Or… bit more dirty but definitely feasible:
Place the loop in a try catch, and throw a specific error instead of the break. Catch that error and consider it a non-errored exit of your loop.

No its Statement.DoWhile not the one u mentioned

Hi,

It’s very old DoWhile activity.

Can you try to put new DoWhile activity and check its name?

Regards,