# if

&#x20;X3 programming language, the "if" keyword is used for conditional execution. It allows you to execute a block of code only if a specified condition evaluates to true. Here's how you would use the "if" keyword in your X3 language:

#### Basic Usage:

```x3
var x = 10

# Using 'if' to check a condition
if x > 5 then
    show("x is greater than 5.")
end
```

#### Explanation:

* In this example, the "if" statement checks if the variable `x` is greater than 5.
* If the condition `x > 5` evaluates to true, the code inside the "if" block (in this case, printing "x is greater than 5") will be executed.

#### Else Clause:

```x3
var x = 3

# Using 'if' with 'else' to handle alternate case
if x > 5 then
    show("x is greater than 5.")
else
    show("x is not greater than 5.")
end
```

#### Explanation:

* Here, if the condition `x > 5` is false, the code inside the "else" block will be executed.

#### Elif Clause (Else If):

```x3
var x = 5

# Using 'if' with 'elif' to check multiple conditions
if x > 5 then
    show("x is greater than 5.")
elif x == 5 then
    show("x is equal to 5.")
else
    show("x is less than 5.")
end
```

#### Explanation:

* In this example, if the first condition `x > 5` is false, the "elif" clause (`x == 5`) will be checked.
* If `x` is neither greater than 5 nor equal to 5, the code inside the "else" block will be executed.

#### Nested 'if' Statements:

```x3
var x = 10
var y = 5

# Using nested 'if' statements
if x > 5 then
    if y > 2 then
        show("Both x and y are greater than their respective thresholds.")
    end
end
```

#### Explanation:

* In this example, the "if" statement inside another "if" statement will only be executed if both conditions (`x > 5` and `y > 2`) are true.

By incorporating the "if" keyword in your X3 language, you provide users with the ability to control the flow of their programs based on specified conditions, enabling more dynamic and responsive behavior.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manis-organization-2.gitbook.io/untitled-1/keywords/conditions-in-x3/if.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
