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

# Advanced logic expressions

> Use the answers from one block as display conditions for the options in the following blocks.

Logic expressions let you "pass" answers from one block to another and use them as display conditions: you decide option by option what to show based on what the respondent has already selected. It's the same logic as *array filter* and *array exclusion*, built into the Exoid Builder.

<Info>
  This requires **Advanced statistics mode**, which you turn on from the interview settings. See [Advanced statistics](/en/advanced/advanced-statistics).
</Info>

## How it works

With the mode on, you reuse the answers of a question in the following blocks. The logic is **always defined in the destination block**, referencing the code of the source question.

<Warning>
  Set the **Question code** (for example `D8`) in the settings of the source block. If the code is left at its default value, the expression can't be evaluated and the logic won't work.
</Warning>

## Full example

Two multiple choice questions in sequence.

<Steps>
  <Step title="D8 - Which shoe brand do you like most?">
    Options: Nike, Adidas, Autry, Hogan. Since it's a multiple choice question, the answers are treated as a set of values.
  </Step>

  <Step title="D9 - Which one do you buy most often?">
    Here you want to show only the options the respondent selected in D8.
  </Step>

  <Step title="Define an expression for each option">
    In multiple choice questions the condition is set option by option, not on the question as a whole.
  </Step>
</Steps>

### Including options

On each option of D9 you set the corresponding display condition.

```text title="Display conditions on the options of D9" theme={"dark"}
Nike:    (D8 contains "Nike")
Adidas:  (D8 contains "Adidas")
Autry:   (D8 contains "Autry")
Hogan:   (D8 contains "Hogan")
```

This way each option in D9 appears only if the corresponding brand was selected in D8. If the respondent chooses Autry and Adidas, only those two conditions are true and D9 shows only those options.

### Exclusion logic

You can also hide an option when a given answer is present, by negating the expression.

```text title="Show Nike only if it was NOT selected in D8" theme={"dark"}
!(D8 contains "Nike")
```

### Single choice case

If D8 were a single choice question, the comparison would be direct instead of set-based.

```text title="Direct comparison" theme={"dark"}
D8 === "Nike"
```

## Passing only specific options

If you want only some options to pass through and block all the others, you set the logic the opposite way: `contains` on the options that must pass, negation on all the others.

Example: pass one of Adidas and Autry (if selected) and one of Nike and Hogan (if **not** selected).

```text title="Expressions on the destination block" theme={"dark"}
Q8 contains "Adidas"
Q8 contains "Autry"
!(Q8 contains "Nike")
!(Q8 contains "Hogan")
```

## Operators used

| Operator   | Syntax                  | When to use it                                                                  |
| ---------- | ----------------------- | ------------------------------------------------------------------------------- |
| `contains` | `D8 contains "Nike"`    | Checks whether a value is among the answers of a multiple choice question.      |
| `!(...)`   | `!(D8 contains "Nike")` | Negates the condition: shows the option only if the value was **not** selected. |
| `===`      | `D8 === "Nike"`         | Direct comparison on a single choice question.                                  |

## Next steps

<CardGroup cols={2}>
  <Card title="Carry forward options" icon="arrow-right-left" href="/en/logic/carry-forward">
    Automatically bring the answers of one question into the next one, without writing expressions.
  </Card>

  <Card title="Logic and conditions" icon="git-branch" href="/en/logic/conditions">
    Build the interview paths with the Go To system.
  </Card>
</CardGroup>


## Related topics

- [Advanced statistics mode](/en/advanced/advanced-statistics.md)
- [Troubleshooting](/en/troubleshooting.md)
- [What you can do with Exoid](/en/capabilities.md)
