> For the complete documentation index, see [llms.txt](https://docs.taco.build/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.taco.build/for-developers/conditions/logical-conditions/ifthenelsecondition.md).

# IfThenElseCondition

The `IfThenElseCondition` allows for conditional branching, where different conditions are executed based on the outcome of an initial "if" condition. It operates with a simple "if-then-else" structure and provides flexibility in determining the behaviour when a condition is true or false.

A condition that allows for if-then-else branching based on underlying conditions\
i.e. **IF** `CONDITION_A` **THEN** `CONDITION_B` **ELSE** `CONDITION_C`.

It is composed of:

* `ifCondition`: A required field that specifies the condition to be evaluated first. If the condition evaluates to `true`, the `thenCondition` is executed; if it evaluates to `false`, the `elseCondition` is executed.
* `thenCondition`: A required field that specifies the action or condition to execute if the `ifCondition` evaluates to `true`.
* `elseCondition`: A required field that specifies the action or condition to execute if the `ifCondition` evaluates to `false`. This can be a `CONDITION`or a boolean value (`true` or `false`), specifying the result when the `ifCondition` is `false`. This gives users control over what the overall condition returns when the `ifCondition` is false.

When combined with other conditions (e.g., `SequentialCondition`, `CompoundCondition`), the `IfThenElseCondition` allows for complex, branching workflows.

## Examples

### IF `conditionA` then `conditionB` else `conditionC`

```typescript
import { conditions } from '@nucypher/taco';

const conditionA = ...
const conditionB = ...
const conditionC = ...

const condition = new conditions.ifThenElse.IfThenElseCondition({
  ifCondition: conditionA,
  thenCondition: conditionB,
  elseCondition: conditionC,
});
```

### IF `conditionA` then `conditionB` else True

```typescript
import { conditions } from '@nucypher/taco';

const conditionA = ...
const conditionB = ...

const condition = new conditions.ifThenElse.IfThenElseCondition({
  ifCondition: conditionA,
  thenCondition: conditionB,
  elseCondition: true,
});
```

### Nested `IfThenElseCondition`

```typescript
import { conditions } from '@nucypher/taco';

const conditionA = ...
const conditionB = ...
const conditionC = ...
const conditionD = ...

const nestedIfThenElseCondition = new conditions.ifThenElse.IfThenElseCondition({
  ifCondition: conditionA,
  thenCondition: conditionB,
  elseCondition: false,
});

const condition = new conditions.ifThenElse.IfThenElseCondition({
  ifCondition: conditionC,
  thenCondition: conditionD,
  elseCondition: nestedIfThenElseCondition,
});
```

{% hint style="info" %}
Individual conditions within the `IfThenElseCondition` can use different chain IDs as long as the chain IDs are supported by the `domain` network being used.
{% endhint %}

## Development References

* Client-side: <https://github.com/nucypher/taco-web/pull/593>
* Server-side: <https://github.com/nucypher/nucypher/pull/3558>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.taco.build/for-developers/conditions/logical-conditions/ifthenelsecondition.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
