what are the differences between do while and while activity in uipath
while :
The While activity checks the condition before executing the loop body. It follows this sequence:
- Checks the condition.
- If the condition is true, it executes the loop body.
- After executing the loop body, it again checks the condition.
- If the condition is still true, it continues executing the loop body.
- This process repeats until the condition becomes false.
- If the condition is initially false, the loop body is not executed at all.
do while :
The Do While activity, on the other hand, checks the condition after executing the loop body. It follows this sequence:
- Executes the loop body.
- After executing the loop body, it checks the condition.
- If the condition is true, it continues executing the loop body.
- This process repeats until the condition becomes false.
- If the condition is initially false, the loop body is executed at least once.
Implementation in UIpath Studio:
while :
- Drag and drop the While activity from the Activities panel.
- Specify the condition by clicking on the “Condition” field in the properties of the While activity. You can either enter a Boolean expression directly or use variables, arguments, or expressions to define the condition
- Inside the While activity, place the sequence of activities that you want to repeat as long as the condition is true. You can add any number of activities inside the loop body.
- After defining the loop body, the While activity will check the condition. If the condition is true, it will execute the activities inside the loop body. If the condition is false, it will skip the loop body and proceed to the next activity following the While activity.
After executing the loop body, the While activity goes back to step 4 and checks the condition again. If the condition is still true, it repeats the execution of the loop body. This process continues until the condition becomes false.
do while :
- Drag and drop the Do While activity from the Activities panel onto the designer canvas.
- Specify the condition by clicking on the “Condition” field in the properties of the Do While activity. You can either enter a Boolean expression directly or use variables, arguments, or expressions to define the condition.
After executing the loop body, the Do While activity checks the condition. If the condition is true, it goes back to step 4 and repeats the execution of the loop body. If the condition is false, it exits the loop and proceeds to the next activity following the Do While activity.
while vs do while
Aspect | While Activity | Do While Activity |
---|---|---|
Condition Check | Checked before executing the loop body | Checked after executing the loop body |
Initial Execution | Skips the loop body if the condition is initially false | Executes the loop body at least once, regardless of the initial condition |
Loop Execution | Continues executing the loop body as long as the condition is true | Repeats executing the loop body as long as the condition is true |