Alternative to nesting T/Cs to try running code x time?


I need to re-run a sequence x times then give up if it did not work. So far, I “solved” by nesting try-catch to invoke the workflow - but this is like totally inelegant and inflexible.

Does anyone know how I could replicate the code below in UiPath Studio (below is an example for an Excel Macro)

Thanks in advance!

Sub learnToDance()
    Dim tryCounter As Integer: tryCounter = 0
    On Error GoTo tryagain
    If tryCounter < 3 Then
        tryCounter = tryCounter + 1
        Exit Sub
        Exit Sub
    End If
    On Error GoTo -1
    GoTo risky
End Sub

Sub tryDancing()
    Error ("oops, I can't dance")
End Sub

Sub giveUp()
End Sub

Back to answer to myself :crazy_face:

This is what I came up with - just in case someone has a better idea or runs into the same problem…