> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xpressbot.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Flow Logic: If and Switch

> Show different content on a WhatsApp Flow screen depending on what the customer answered, using the If and Switch elements and their branches.

## What is this?

**If** and **Switch** are the two elements in the **Logic** group of the **Add content** palette in the [Flow Builder](/workspace/whatsapp/flows/builder). They make part of a screen appear only for some customers, based on answers they have already given:

* **If** — "Show content only when a condition is true." You choose a question, how to compare it, and the answer to look for, then write what to show when it's true (**Then**) and, optionally, what to show instead (**Else**).
* **Switch** — "Show different content for each answer." You choose a question, then write the content to show for each answer it can have.

You never type any code: the builder writes the expression WhatsApp needs from the choices you make. (If you want to, **Edit as text** lets you see and change it.)

\[SCREENSHOT: flows-logic-if-condition — The settings panel for an If element showing the Show this when rule with a question, a comparison, and an answer, the Add condition button, and the Then and Else sections]

<Info>
  Logic can look at the answers to questions on the **same screen** and on **earlier screens**. The question must have a **Field name**.
</Info>

## What can I do here?

* Add an **If** with one or more conditions, joined by "all must be true" or "any can be true"
* Add a **Switch** with one case per answer
* Fill each branch with headings, body text, captions, or copies of questions from the same screen
* See a plain-words summary of the rule right in the screen preview

## How to use it

### Add an If

<Steps>
  <Step title="Add the question first">
    An **If** reacts to a customer's answer, so the screen (or an earlier screen) needs a question. If there isn't one yet, the **If** settings say **Add a question first** — "If and Switch react to what the customer answers. Add a question to this screen, then choose it here." — and offer quick buttons for **Single choice**, **Dropdown**, **Short answer**, **Date picker**, and **Opt-in**. A question added this way is placed just above the **If**.
  </Step>

  <Step title="Add the If">
    In the palette's **Logic** group click **If** (or drag it onto the screen). Select it in the preview to open its settings.
  </Step>

  <Step title="Build the condition">
    Under **Show this when**, choose a question from **Choose a question**. Questions are grouped as **This screen** and **Earlier screens** (earlier ones show the screen title after the label). Next choose how to compare, then the answer.
  </Step>

  <Step title="Fill Then and Else">
    Add what customers see when the condition is true under **Then: show this** and, optionally, what they see otherwise under **Else: show this instead**. See [Fill a branch](#fill-a-branch).
  </Step>
</Steps>

**How to compare.** The comparisons offered depend on the kind of question:

| Question | Comparisons |
| - | - |
| **Short answer** set to **Number** | **is**, **is not**, **is more than**, **is at least**, **is less than**, **is at most** |
| **Short answer** (other types), **Paragraph**, **Date picker**, **Calendar** (single date) | **is**, **is not**, **is empty**, **is not empty** |
| **Single choice** and **Dropdown** with options you typed | **is**, **is not**, **is empty**, **is not empty** — and the answer is picked from a list (**Choose an answer**) |
| **Opt-in** | **is ticked**, **is not ticked** |

For other comparisons you type the value into **Type a value** (a number box for numbers, a date box for dates). **Single choice** and **Dropdown** whose options load from an endpoint are compared as text. **Multiple choice**, **Chips**, **Upload**, and a **Calendar** set to a date range can't be used in a condition — WhatsApp can't compare them, so they don't appear in the list.

**Several conditions.** Click **Add condition** for another row, and the trash icon (**Remove condition**) to delete one. Once there is more than one, choose **All must be true** or **Any can be true**. A row only counts once it is complete — an unfinished row (no answer picked yet) is ignored. Below the rules, **Shown when:** gives a plain-words summary such as "Which department? is Dental and Age is at least 18".

**Edit as text.** Click **Edit as text** to see the condition WhatsApp will receive and edit it directly. If a condition was written by hand in a way the rule builder can't show, you'll see "This condition was written by hand, so it can't be shown as rules. Edit it here, or start over with rules." — click **Start over with rules** to build it again with the picker.

**In the preview.** The **If** appears as a dashed box saying **Show when** followed by the rule in words, with a second line such as **Then: 1 · Else: 0** counting the items in each branch. Until you pick a question it says **Choose what this depends on**.

### Add a Switch

<Steps>
  <Step title="Add the Switch">
    In the **Logic** group click **Switch** and select it in the preview.
  </Step>

  <Step title="Pick the question">
    Under **Switch on question**, choose the question. If the screen has no questions yet you'll see **Add a question first**, as with **If**.
  </Step>

  <Step title="Add a case for each answer">
    Under **Add a case for each answer**, click an answer to add its case, or **Add every answer** to add all the remaining ones at once. The message **Every answer has a case.** appears when none are left. For a **Single choice** or **Dropdown** with options you typed, the answers are those options; for an **Opt-in** they are `true` and `false`.
  </Step>

  <Step title="Fill each case">
    Each case is headed **When** *question* **is** *answer*, with a trash icon to delete the case. Fill it in as described in [Fill a branch](#fill-a-branch).
  </Step>
</Steps>

For questions without a fixed list of answers (a **Short answer**, **Paragraph**, **Date picker**, or a choice question that loads from an endpoint), type the value into **Answer to match** and click **Add case**. Those cases are headed **When the answer is** with an editable box so you can change the value later. Before any case exists you'll see "No cases yet. Add a case for each value the field can have."

\[SCREENSHOT: flows-logic-switch-cases — The settings panel for a Switch element with Switch on question, the answer buttons, Add every answer, and two cases each with its own content]

In the preview a **Switch** says **Different content for each answer to** followed by the question, and **2 cases** (the number of cases).

### Fill a branch

Each **Then**, **Else**, or **Switch** case has the same editor.

\[SCREENSHOT: flows-logic-branch-editor — A branch with a text block (type selector and text box), a copied question, the Remove button, and the Add content menu open]

* With nothing in it, it says "Nothing here yet. Add the text or question to show."
* Click **Add content** to open a menu. Choose **Large heading**, **Small heading**, **Body**, or **Caption** to add a text block with the starting text **Your text here**. Under **Copy a question from this screen**, choose a question already on the screen to copy it into the branch.
* A text block has a dropdown to switch between heading, body, and caption, and a **Type the text to show** box to write the words.
* A copied question shows its label with "(copied from this screen)" after its type. You can't edit it inside the branch — change the original, or use the trash icon (**Remove**) to take the copy out.

Only some questions can be copied into a branch: **Multiple choice**, **Date picker**, **Dropdown**, **Link**, **Image**, **Opt-in**, **Single choice**, **Paragraph**, **Short answer**, and **Chips**. Text, logic, and the Button are not in the list. Other elements can't go inside a branch.

**Then** must contain at least one item. **Else** is optional.

## Troubleshooting / Technical Notes

* **"Add a question first."** The **If** or **Switch** has nothing to react to. Add a question (the quick buttons add one above the **If** or **Switch**) or move the logic to a later screen.
* **The question I want isn't in the list.** Only questions on this screen and earlier screens appear, only if they have a **Field name**, and not **Multiple choice**, **Chips**, **Upload**, or a **Calendar** set to a date range.
* **Save says "invalid condition".** The condition is incomplete or was typed by hand with a mistake. The message ends with the reason in brackets — for example it must refer to at least one question, text values need quotes, and `===` or `and` aren't allowed. Rebuild it with the question picker, or use **Start over with rules**.
* **Save says "then branch must contain at least one component".** Add something to **Then: show this**.
* **Save says "value is required" or "at least one switch case is required".** Choose a question under **Switch on question** and add at least one case.
* **My condition shows "Choose what this depends on" in the preview.** No complete rule exists yet — pick a question, a comparison, and an answer.
* **A branch can't hold the element I want.** Branches take text blocks and copies of simple questions only. Put other content on the screen itself, or on its own screen.

## Related docs

* [Flow Builder](/workspace/whatsapp/flows/builder)
* [Flow content and settings](/workspace/whatsapp/flows/content-and-settings)
* [Dynamic options and endpoints](/workspace/whatsapp/flows/dynamic-data)
* [Flows](/workspace/whatsapp/flow)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.