> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/automate-using-testview/test-commands-reference/general/if-expression.md).

# If(expression)

## Description

This command calls the ScopeView solver to evaluate the expression (same as **Eval** and **Expression** commands). Therefore, it is possible to use the functions available with its calculation engine. Each 'if' expression in a loop is evaluated prior to the beginning of a loop. However, it does not execute the content at the beginning of a loop (no matter if the result is true or false).

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-f408d4165dd5525291a5fdd0ef4b1a9bcacdf5f0%2Fimage%20(1273).png?alt=media" alt=""><figcaption></figcaption></figure>

**Example:** Suppose you want to do: if( max( breaker current phase A > 500)) inside a loop where the breaker is Di1. The script cannot access directly the signals from the signal key of the Processing command. Therefore, you need first to assign a variable to this signal in the processing (it can be a whole signal, in opposition to post-processing that can only accept scalar values). ![](https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-ae682c0989c0f22953129186a04dc393e4383d27%2Fimage%20\(1275\).png?alt=media)

The 'if' expression would then be: ![](https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-376c9f741394ae19d363a0d6809f57800285999e%2Fimage%20\(1274\).png?alt=media)

In this case, if the variable is not initialized, it will cause an error and terminate de test sequence because it tries to evaluate if a string is bigger than 500 (“NotFound > 500”).

Thus, you need to initialize the variable before the loop using the Assign command: ![](https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-67da4a613db5496d516bdae751d5f80e65130156%2Fimage%20\(1276\).png?alt=media)

The initial value does not matter if the Processing command is executed before the if expression (HypProc will overwrite the variable).

**Note:** Initialization is not always necessary. For instance, <img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-1300685649a14a9af2aa26b13e4883932c0fdf9e%2Fimage%20(1277).png?alt=media" alt="" data-size="line">will not terminate the test sequence even if the variables are not defined because it is a “!=” operator (comparing strings does not cause an error with this operator).

**Some accepted operators:**

| **&&**        | And          |
| ------------- | ------------ |
| **\|\|**      | Or           |
| **!**         | Not          |
| **<, <=**     | LT, LTE      |
| **>, >=**     | GT, GTE      |
| **!=**        | Different    |
| \*\*/, \*\*\* | Div., multi. |
| **+, -**      | Plus, minus  |
| **%{var}**    | Variable     |


---

# 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://www.opal-rt.com/docs/hypersim/automation-api-and-scripting/automate-using-testview/test-commands-reference/general/if-expression.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.
