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

# If-Else

<CardGroup cols={2}>
  <Card title="Bool, Any, Any" href="#bool-any-any" />

  <Card title="Bool Field, Scalar Field, Scalar Field" href="#bool-field-scalar-field-scalar-field" />

  <Card title="Bool Field, Vector Field, Vector Field" href="#bool-field-vector-field-vector-field" />

  <Card title="Bool Field, 2D Vector Field, 2D Vector Field, 5.31.0" href="#bool-field-2d-vector-field-2d-vector-field-5310" />
</CardGroup>

***

## About this Block

### What it does:

The **If-Else** block provides control flow to your nTop workflow, enabling it to make decisions based on a condition. It evaluates the boolean *Condition* input and returns the *Then* branch if the *Condition* is true or the Else branch if the *Condition* is false. We will refer to both *Then* and *Else* outputs as "branches." Below is a common schematic of the If-Else.

![If Else Flow Chart](https://storage.googleapis.com/files-learn/static/ExtendedBlockDocs/if_else_flow_chart.png)

### Running:

To better understand **If-Else**, it is important to understand how the nTop notebook blocks are ran. When you place blocks into the notebook, the block will always run unless:

* The block’s required inputs are empty
* The block is set to Manual Run Mode
* Any block referenced by the block upstream does not have its required inputs entered
* Any block referenced by the block upstream is set to Manual Run Mode
* Autorun is toggled off

**If-Else** works differently than other nTop blocks - when set up correctly, only the *Then* or *Else* branch will run based on the Condition, returning that output value to the **If-Else** block. Your nTop workflow not running the unneeded branch is beneficial if you run computationally expensive workflows (e.g., meshing) or have a branch that produces a failure.

**Common uses:**

* General Logic
* Mesh Setup
* Simulation Setup
* Scan Data Alignment
* Field Logic

**Tips:**

* When **If-Else** branches are made into variables, they will always run. When running computationally expensive branches of **If-Else**, we recommend not making the branches variables.

  ![If Else Example](https://storage.googleapis.com/files-learn/static/ExtendedBlockDocs/if_else_running.gif)

* We recommend only referencing the **If-Else** output properties downstream, not the output properties from either of the branches. If you do reference the output properties of a branch downstream, nTop will require this branch to run regardless of the *Condition*.

  * If needed, create branch nestings and make variables of lower-level nestings.
    * The bracket example below shows the correct setup.
    * The "Implicit->Mesh," "Amount," and "Edge length" variables are used in both branches of **If-Else** so that they can be kept as variables outside of **If-Else**.
    * (Red Arrow) The "Simple" mesh is self-intersecting. In this instance, the output property of the "self-intersecting" boolean equals True and is used as the *Condition*.
    * Due to the *Condition* being True, only the "Then - Volume Mesh" branch runs, providing a suitable mesh.
    * Due to the *Condition* being True, the "Else - Volume Mesh" branch does not run and returns an error.

  ![If Else Example Self-intersection](https://storage.googleapis.com/files-learn/static/ExtendedBlockDocs/if_else_example_self_intersection.png)

* When creating notebooks, you will likely create the blocks you need in the notebook and then drag them into the branches of the **If-Else**.
  * These blocks will run automatically until they are used as Branches in **If-Else** - in which case only the one that matches the *Condition* input will run. This is very helpful for reusable workflows.
  * If you want to ensure neither branch is ever run, ensure the *Condition* is unbuilt or in Manual Run Mode, then create your logic encapsulated in the If-Else via the input dropdown.

* The two overloads of **If-Else** enable you to leverage a Bool Field *Condition* to return either a Scalar Field or Vector Field value. Since evaluating fields leverages mathematics, both branches will always run for these overloads and be computationally fast.

  ![If Else Example Bool Field Overloads](https://storage.googleapis.com/files-learn/static/ExtendedBlockDocs/if_else_example_bool_field_overloads.gif)

***

<h2 id="bool-any-any">
  Bool, Any, Any
</h2>

Returns a value based on a given condition.

### Inputs

| Name      | Type                                               | Description                           |
| --------- | -------------------------------------------------- | ------------------------------------- |
| Condition | [Bool](../../../../block-documentation/types/bool) | Condition used to evaluate execution. |
| Then      | [Any](../../../../block-documentation/types/any)   | Output when the Condition is True.    |
| Else      | [Any](../../../../block-documentation/types/any)   | Output when the Condition is False.   |

### Outputs

| Type                                             |
| ------------------------------------------------ |
| [Any](../../../../block-documentation/types/any) |

***

<h2 id="bool-field-scalar-field-scalar-field">
  Bool Field, Scalar Field, Scalar Field
</h2>

Returns a field of values evaluated based on a given condition.

### Inputs

| Name      | Type                                                               | Description                                                               |
| --------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------- |
| Condition | [Bool Field](../../../../block-documentation/types/bool-field)     | Condition used to evaluate execution at a field point.                    |
| Then      | [Scalar Field](../../../../block-documentation/types/scalar-field) | Output when the field value of Condition is True at the evaluated point.  |
| Else      | [Scalar Field](../../../../block-documentation/types/scalar-field) | Output when the field value of Condition is False at the evaluated point. |

### Outputs

| Type                                                               |
| ------------------------------------------------------------------ |
| [Scalar Field](../../../../block-documentation/types/scalar-field) |

***

<h2 id="bool-field-vector-field-vector-field">
  Bool Field, Vector Field, Vector Field
</h2>

Returns a field of values evaluated based on a given condition.

### Inputs

| Name      | Type                                                               | Description                                                               |
| --------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------- |
| Condition | [Bool Field](../../../../block-documentation/types/bool-field)     | Condition used to evaluate execution at a field point.                    |
| Then      | [Vector Field](../../../../block-documentation/types/vector-field) | Output when the field value of Condition is True at the evaluated point.  |
| Else      | [Vector Field](../../../../block-documentation/types/vector-field) | Output when the field value of Condition is False at the evaluated point. |

### Outputs

| Type                                                               |
| ------------------------------------------------------------------ |
| [Vector Field](../../../../block-documentation/types/vector-field) |

***

<h2 id="bool-field-2d-vector-field-2d-vector-field-5310">
  Bool Field, 2D Vector Field, 2D Vector Field, 5.31.0
</h2>

Returns a field of values evaluated based on a given condition.

### Inputs

| Name      | Type                                                                     | Description                                                               |
| --------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------- |
| Condition | [Bool Field](../../../../block-documentation/types/bool-field)           | Condition used to evaluate execution at a field point.                    |
| Then      | [2D Vector Field](../../../../block-documentation/types/2d-vector-field) | Output when the field value of Condition is True at the evaluated point.  |
| Else      | [2D Vector Field](../../../../block-documentation/types/2d-vector-field) | Output when the field value of Condition is False at the evaluated point. |

### Outputs

| Type                                                                     |
| ------------------------------------------------------------------------ |
| [2D Vector Field](../../../../block-documentation/types/2d-vector-field) |
