What is a Switch?

You are currently viewing What is a Switch?

A switch statement is a conditional statement that runs an expression and tests the result against a list of values, called cases. If any cases are match the expression result, the automation will perform the associated activities, otherwise if no case matches the expression result, the automation will perform any associated activities for the default case. 

Switch statements are one of the foundational concepts in programming and allow an automation to make decisions from multiple options while it’s running. They enable a single course of action, out of two or more separate options depending on the result of the switch expression. 

A Switch is just like an if statement, except a switch can have more than two options.

Switch statements contain three major components, an Expression, Case(s), and a Default Case:

  • Expression – Contains a programming expression with multiple outcomes. This expression is analyzed during the switch and based on the result, the switch will then start running the case statement most appropriately matching the expression result.
  • Case(s) – This section is performed if the expression result matches the case. There can be one or more distinct cases in a switch statement. There cannot be duplicate case statements.
  • Default Case – This section is performed when the expression does not match any of the other case(s).

What Does An Switch Look Like?

How to use a Switch in UiPath?

In UiPath, switch statements can be added to automations using either one of two activities, the Switch activity when using a sequence or a Flow Switch activity when using a flowchart. To learn more about sequences and flow charts, click here. Let’s take a look at what these two activities look like:

  • Switch activity – used for if statements in sequences.
  • Flow Switch – used for if statements in flowcharts.