Break or Continue for while loops

Referring to thread Exit loop when condition is met

Break and Continue activities are only for For Each loops, and I don’t see any custom code that works with the same functionality.

How do I break or continue midway through a while loop?

@DEATHFISH,

You can use Invoke code activity for this.

Cheers,
Pankaj

Any sample screenshots/code/attachments? Thanks

please write a code in invoke activity and run it

BreakWithWhile

Cheers,
Pankaj

1 Like

Hi @DEATHFISH,

You just need to add a flag in loop and add this flag in while condition.

Thanks,
Aisling

@aisling.bai, that won’t work. Just tested it.

Sorry to necro but I’m running into the same issue.
There are ways around it, none of which include using a code block (because I would need to be able to write scrape tasks in code and I’m not subjecting myself to that in a language I’m not familiar or comfortable with).

The only way around it, in code form, would be to do something like this:

GenericValue aastate = IsButtonEnabled("button1", "aastate");
while (aastate.ToString().Contains("unavailable"))
{
    // snip
    aastate = IsButtonEnabled("button1", "aastate");
}

It works, but it’s not the most efficient and WWF leaves me lacking confidence in its ability to work properly. I would rather be doing something like this:

while (true)
{
    GenericValue aastate = IsButtonEnabled("button1", "aastate");
    if (aastate.ToString().Contains("unavailable")
        break;

    // snip
}

So while I understand the work-around, it leaves me in a place where I’m having to double-up some operations in order to keep things functioning properly. Is this a restriction with WWF or with UiPath Studio?

Try this custom activity https://go.uipath.com/component/while-loops-with-break-and-continue-activities