I’m currently working in UiPath Studio (version 25.10.11 and above) and I’m looking for a way to rerun or “loop” a specific chunk of code.
I’m aware of the Retry Scope activity, but it only retries execution when an exception is thrown within the scope. In my case, I’d like to repeat a sequence when no exception occurs.
Of course, I could implement this using a While or Do While loop with a defined maximum number of iterations, but that feels a bit like a workaround rather than a clean or best-practice solution.
Is there a more appropriate or built-in activity to handle this kind of scenario?
Actually looping ís the best practice way to repeat ‘chunks’ of code.
A do while with a max iteration can work, or the repeat activity to make it really static.
If it is your whole process that requires multiple runs, configure your triggers in the orchestrator to repeat themselves / run multiple instances.
Without a defined exit condition or maximum number of iterations, any loop could run indefinitely and never stop.
If your goal is to repeat a sequence a specific number of times or until a condition is met, then using While, Do While, or Repeat Number of Times is actually the recommended approach rather than a workaround.
Could you share your requirement in a little more detail? That may help identify a more suitable approach.
you can use a combination of a Try-Catch inside a conditional loop construct. something like below:
foreach(int i in numbers)
{
Try
{
//your code or method calls goes in here...
}
//decide whether to reset the exception and continue the loop/ break the loop on an exception.
Catch(DivideByZeroException Dbze)
{
Continue;
}
Catch(ArgumentException AE)
{
Break;
}
Catch(Exception GenEx)
{
Break;
}
}