# IF, Switch and Merge — AI Automation with n8n

Source: https://www.geekswithgeeks.com/en/n8n-ai-automation/core-branching

> Route items by conditions and join branches back together.

## Decide, then rejoin

**IF** splits items into a true and a false branch. **Switch** sends each item to one of several outputs, like a router. **Merge** joins two branches again, either by position, by matching a key (like a database join) or by appending all items. Items on the unused branch simply do not continue, which is a normal outcome, not an error.

## A routing table

A Switch node with rules on a `category` field. The fallback output catches anything unexpected so no item is silently lost.

```text
Switch on {{ $json.category }}
  billing   -> Create finance ticket
  technical -> Create engineering ticket
  sales     -> Notify sales channel
  fallback  -> Send to a human review queue
```

**Quiz:** Why configure a fallback output on a Switch node?

- [x] To catch unexpected values so no item is silently lost
- [ ] Switch cannot run without it
- [ ] To make workflows slower
- [ ] To delete the data

*Answer:* To catch unexpected values so no item is silently lost. Without a fallback, an item matching no rule goes nowhere and nobody notices.
