# Switch

> Configure the Switch node, write its case expressions, and choose between Switch and Decision, with examples.

## What it does

Routes a workflow to one of several paths based on ordered conditions. The first condition that matches is taken.

## Choosing between Switch and Decision

| Use Switch when... | Use Decision when... |
|---|---|
| You have three or more outcomes | You have exactly two outcomes |
| You're routing by multiple distinct conditions | The condition is a simple yes/no |
| You need a default/fallback branch | |

## Configuration reference

| Field | Required | Default | Description |
|---|---|---|---|
| **Cases** | Yes | 2 empty cases | Ordered branch list. Each case has a handle label and a JavaScript expression; the first truthy expression is taken. |
| **Include default** | No | `true` | Whether to add a Default branch that is taken when no case expression matches. |

## Writing case expressions

Each case expression uses the same JavaScript environment as the Script and Decision nodes:

```javascript
// Case 1: high priority
$vars.ticket1.output.priority === "high"

// Case 2: medium priority
$vars.ticket1.output.priority === "medium"

// Case 3: low priority (or use Default to catch everything else)
$vars.ticket1.output.priority === "low"
```

More specific conditions should appear first. A broader condition higher in the list will match before a more specific one below it.

## Examples

### Example 1: Route by HTTP status code

| Case | Expression | Branch |
|---|---|---|
| Success | `$vars.httpRequest1.output.code === 200` | process the response |
| Not Found | `$vars.httpRequest1.output.code === 404` | handle the missing resource |
| Default | (fallback) | handle the unexpected error |

### Example 2: Route by string value

| Case | Expression | Branch |
|---|---|---|
| Approved | `$vars.form1.output.status === "approved"` | continue the workflow |
| Rejected | `$vars.form1.output.status === "rejected"` | notify the rejection |
| Pending | `$vars.form1.output.status === "pending"` | wait for review |
| Default | (fallback) | handle the unknown status |

## Next steps
- [Decision node](node-decision.md): branching into exactly two paths.
- [Variables and data flow](variables-and-data-flow.md): `$vars` syntax and expression patterns.
- [Error handling](error-handling.md): handling failures, which differs from conditional branching.
- [Community](community.md): ask questions and share workflows with other builders on the UiPath Forum.
