# IF and Switch

Branching nodes: send items down different paths based on a condition.

AI developers · Part 08: n8n · Card 6 of 13 · Last updated 2026-10-13

## Analogy

if/else and switch, drawn as forks in the road.

## In an agent

Typical use: if the agent says risk is high, alert the tech lead; otherwise post to the normal channel.

## Questions people ask

### How do I branch a workflow in n8n?

Use the IF node for a yes or no condition and the Switch node for several cases. Each sends items down a different path based on their data. For example, an IF node can check whether the agent rated a pull request as high risk and route it to a different Slack channel.

### How do I route an agent's result in n8n?

Have the agent return structured output, such as a risk field with low, medium or high. Then add an IF or Switch node that reads that field from $json and sends each case down its own path: alert the tech lead for high risk, post to the normal channel otherwise.

## Related concepts

- [n8n](https://studyvisually.com/learn/tech/ai-developers/n8n/n8n)
- [Trigger node](https://studyvisually.com/learn/tech/ai-developers/n8n/trigger-node)
- [Action node](https://studyvisually.com/learn/tech/ai-developers/n8n/action-node)
- [$json](https://studyvisually.com/learn/tech/ai-developers/n8n/json-item)

Web page: https://studyvisually.com/learn/tech/ai-developers/n8n/if-switch
Study this card in the app: https://studyvisually.com/app/learn?category=ai-developers&card=if-switch
