Control Flow
What is Control Flow?
Control flow is a programming concept that refers to the order in which individual activities are executed.
In Uipath, you can control the flow of your automations by using certain activities that give you the option to go down multiple pathways, repeat activities and even assist in decision making.
The primary types of control flow that are used in UiPath are Conditional Statements and Loops which are discussed in greater detail below.
- Conditional Statements – Activities that decide the flow or direction of an automation.
- Loops – Activities used to repeat until a certain condition is met.
What are Conditional Statements?
Conditional Statements refers to the use of activities that assist in deciding the flow or direction of an automation.
Conditional Statements primarily consist of a statement with 2 or more options or pathways the robot can go down. Based on the option chosen, the direction of the automation will change. This allows for a more dynamic automation that can go down multiple pathways depending on the inputs received.
It is very helpful to think about conditional statements in a spoken language:
“If condition A is true, let’s follow a set of instructions, otherwise if it is false, let’s do something else”
The primary Conditional Statements used in UiPath are the If activity and Switch activity for sequences and the Flow Decision and Flow Switch for flowcharts. If activities and Flow Decisions have only 2 options to choose from, whereas a Switch and Flow Switch can have 2 or more.
Some examples of Conditional Statements includes:
-
If
The If activity contains a statement and two conditions (Then or Else). The Then section is executed if the statement is true, while the Else section is executed if the statement is False. Can only be used in Sequences.
-
Flow Decision
An activity that executes one of two branches (True or False), depending on whether a specified condition is met. A Flow Decision is equivalent to the If activity. Can only be used in Flowcharts.
-
Switch
The Switch activity allows you to select one choice out of multiple, based on the value of a specified expression. Can only be used in Sequences.
-
Flow Switch
The Flow Switch activity allows you to select one choice out of multiple, based on the value of a specified expression. Can only be used in Flowcharts.
What are Loops?
Loops are programming structures used to automate repetitive tasks by repeating the same activity or activities over and over again (also known as iterating) until a certain condition is met. Loops can be used both in Flowcharts and Sequences.
Since repetitive tasks are common in programming and business applications, loops play an essential role in automation development in order to save time and minimize errors. Loops save development time as any activities loop only needs to be created once, but can be run multiple times during an automation.
They also save automation run time as iterating through a loop can be faster than having the robot run through separate activities. Loops also help minimize errors as each iteration is not a separate workflow, but a single loop, which can be modified once and be updated for all iterations.
If you want to exit a loop before all the iterations have been completed, you can use the Break activity. The Break activity immediately exits the loop and moves onto any code that follows it. To learn more about how to exit a loop with the break activity, click here.
Some examples of loops used in UiPath include:
-
While
The while loop works by repeating a given set of actions while a specified condition is true,. A while loop checks if the condition is true BEFORE proceeding with the body of the loop.
-
Do While
The Do While loop works by repeating a given set of actions while a specified condition is true. A Do While loop checks if the condition is true AFTER processing the body of the loop.
-
For Each
The For Each loop works by iterating through a list of items, one at a time and executing whatever actions are placed within the body of the loop.
-
For Each Row
The For Each Row loop works by iterating through a DataTable, row by row, and executing whatever actions are placed within the body of the loop. This type of loop can only be used with DataTable data types.