# Conditions

A **conditional** **statement** allows to evaluate one or more conditional instructions. Depending on the result, a block of code can be either executed or skipped. [Conditional statements](https://en.wikipedia.org/wiki/Conditional_\(computer_programming\)) can be found in nearly all programming languages. It is an important part of the control flow.

### Single Condition

A conditional statement starts with an **IF** keyword and ends with an **END** keyword.

#### Syntax

```pascal
if
  <condition>
then
  <consequent>
else
 <alternative>
end
```

`<condition>` - a conditional instruction. This instruction turns the condition result into either `true` or `false.`\
`<consequent>` - a branch of the code that executes if the condition result is `true`.\
`<alternative>` - an optional branch of the code that executes if the condition result is `false`. If `else` is omitted the flow skips the `consequent` branch and continues after a closing `end` keyword.

#### Example

```pascal
if
  is_player_playing 0
then
  0ace: "player is ready"
else
  0ace: "player is not ready"
end
```

Depending on the result of the `is_player_playing` instruction, one or another message will be displayed.

### Multiple Conditions (AND)

`if and` allows to combine up to `8` conditional instructions and execute a block of code if **all of them are `true`**.

#### Syntax

```pascal
if and
  <condition 1>
  <condition 2>
  ...
  <condition 8>
then
  <consequent>
else
  <alternative>
end
```

`<consequent>` - a branch of the code that executes if all conditions are `true`.\
`<alternative>` - an optional branch of the code that executes if any condition is `false`. If `else` is omitted the flow skips the `consequent` branch and continues after a closing `end` keyword.

{% hint style="warning" %}
[Short-circuit evaluation](https://en.wikipedia.org/wiki/Short-circuit_evaluation) is not supported. All conditions are evaluated regardless of the result of the preceding checks.
{% endhint %}

#### Example

Checking if a number is within the given range:

```pascal
int x
if and
  x >= 0
  x <= 10
then
  0ace: "x is between 0 an 10"
end
```

### Multiple Conditions (OR)

`if or` allows to combine up to `8` conditional instructions and execute a block of code if **at least one of them** **is `true`**.

#### Syntax

```pascal
if or
  <condition 1>
  <condition 2>
  ...
  <condition 8>
then
  <consequent>
else
  <alternative>
end
```

`<consequent>` - a branch of the code that executes if any condition is `true`.\
`<alternative>` - an optional branch of the code that executes if all conditions are `false`. If `else` is omitted the flow skips the `consequent` branch and continues after a closing `end` keyword.

{% hint style="warning" %}
[Short-circuit evaluation](https://en.wikipedia.org/wiki/Short-circuit_evaluation) is not supported. All conditions are evaluated regardless of the result of the preceding checks.
{% endhint %}

#### Example

Checking if the vehicle model matches one of the given choices:

```pascal
if or
  model == #PCG600
  model == #FREEWAY
then
  0ace: "model is either PCG600 or Freeway"
else
  0ace: "model is neither PCG600 nor Freeway"
end
```


---

# 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://docs.sannybuilder.com/language/control-flow/conditions.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.
