UiPath Do While Tutorial
A little while ago. I did an example of a while loop in this tutorial. I’d like to show you how the do-while loop works in UiPath. So, to do that, I’m going to create a brand new process. I’m going to call it the UiPath Do While tutorial, click Create here and when the project opens, I’m going to open up the main workflow and I’m just going to drag a do while loop onto the workflow, just like that. Right off the bat, it gives me a little bit of an error message. You might see the red exclamation mark. Now, if you see a red exclamation mark, get your eyes checked because it’s not a red exclamation mark. It’s a white exclamation mark on a red background. But anyways, that’s just a minor point, but the reason that it was barking at me, is it saying, hey, you know, When you have a do while loop, they’re supposed to be some condition that if it’s true, the loop will keep going.
Get Input from user and initialize condition
If it’s false, the loop will exit and so I don’t have a condition like that. Now I’m going to grab user input in this example. So, what I’m going to do is I’m actually going to create a new variable and I’ll just call it user input to type String and of scope sequence there and you can see user input and the condition, which will allow the loop to continue is just whether the user input is equal to Yes and that’s a yes, to the question. Do you want to keep looping? and so the idea of a do while loop is that first of all, the body of the while loop always executes. That’s not true with the while loop. If the condition of a while loop is false. The while loop body will never ever get entered. With a do-while loop, you always enter the body at least once. It’s one of the key differences between a while loop and a do while loop. Now we do have this condition to exit the loop, which is if the user input is not equal to Yes. Exit the loop. If it is yes, keep looping and we have to have some way to manipulate or change that value in the loop.
Specify terminating condition for the loop
Otherwise, it just becomes an infinite loop and it’ll just consume all of our clock cycles on the CPU. So, to do that, I’m just going to drag a user input activity here. The dialog title would be UiPath Do While Loop tutorial, and the label will be, ‘Do you want to keep looping?’. And the input type. I’ll just make it a couple of radio buttons also say yes or no and of course, depending on whether the user, your selection yes or no, the value of that choice in a string can be set to the variable user input. So, I’ll just set user input there as the value. You can do that over in the results tab as well and now when this runs that value yes or no, will update that user input value.
If it’s, yes, we’ll keep looping. If it’s not, we’ll break out. You know what? I might even add a little message box at the top that just says, ‘We are in the loop’. It’s always good to be in the loop because you don’t want to be out of the loop ever. I was going to click control, asked to save that it’s going to go up to the top there, that you can see the beginning of the sequence.You can see the body of the loop, we are in the loop. We get the input dialogue. ‘Do we continue? Yes or no’ and then if that condition is true, we keep looping. If not, we break out of the loop. Oh, the other thing is they need that user input variable declared. So, I had to run the file. So just click run file. It says we are in the loop, right? Because you always entered the loop at least once with a do while loop, as opposed to a while loop where if the condition is false, it will never get entered and now we see these radio bunch. You want to keep looping? Of course, I want to keep looping. This is fun. I love UiPath do while loops. I could use these UiPath do while loops all day long. Okay, I’m tired of it. Now click No and there you go. The application terminates because the condition is now false That’s how the UiPath do while activity works.
UiPath Do While Loop Explained
Test Your Knowledge
- Which of the following are conditional programming activities in UiPath?
- For Each
- In which of the following loops, the body is executed atleast once?
- While loop
- Do While loop
- For Each loop
References that you might want to have a look at :
Learn more about the UiPath Do While Loop activity?
If you’d like more UiPath do while examples, visit the UiPath Forum.