# Conditions

If statements are great, but if you don't need any else if or else statements you don't need to use an if statement, and can use a condition instead.

Conditions are like if statements, except without the leading `if` and trailing `:`. **This means conditions&#x20;*****do not open sections*****,&#x20;*****and you should not indent after on*****e.**

{% hint style="warning" %}
Since conditions do not open sections, this means there is no alternative fork in the logic, there is only one path. Meaning a condition will affect all code underneath it in the same section, not like an if statement that will only affect the lines indented within it.

This also means conditions cannot have an else section.

For example, imagine a player has just finished playing a game:

{% code overflow="wrap" lineNumbers="true" %}

```python
#: Incorrect
{_currentScore} > {highScore}
send "You just set a new highscore!" to player
set {highScore} to {_currentScore}
send "Thanks for playing." to player
```

{% endcode %}

{% hint style="info" %}
For any code after line 2 to be run, `{_currentScore}` must be greater than `{highScore}`.
{% endhint %}

This code is intended to always send the "Thanks for playing." message after the game ends. However, since conditions affect all lines beneath them, the message will only be sent if the user also set a new high score. An if statement must be used to open a section instead, where the code for the high score scenario can be placed:

{% code overflow="wrap" lineNumbers="true" %}

```python
#: Correct
if {_currentScore} > {highScore}:
  send "You just set a new highscore!" to player
  set {highScore} to {_currentScore}
send "Thanks for playing." to player
```

{% endcode %}

{% hint style="info" %}
The if statement opens a new section, allowing the last line to be run even if the condition is not met.
{% endhint %}

Note that is is also possible to reverse the order of these, and send the message before checking for a high score. In this case, a condition is fine as it won't restrict anything.
{% endhint %}

{% hint style="info" %}
Conditions can be used when you don't need to open a section, which also helps keep code cleaner. Not sure why less indents is better? See the [Never Nesting Page](/syntask/organisation/never-nesting.md).
{% endhint %}

Conditions are actually the basic building block that all conditional statements are built around:

{% code overflow="wrap" lineNumbers="true" %}

```python
#: A condition:
1 <= 4
broadcast "Passed"

#: An if-else if-else statement:
if 1 <= 4:
  broadcast "If passed"
else if 8 <= 4:
  broadcast "Else if passed"
else:
  broacast "Else passed"

#: An if any (prinicple is the same for an if all):
if any:
  1 <= 4
  1 <= 5
then:
  broadcast "Passed"

#: The do if effect
broadcast "Passed" if 1 <= 4
```

{% endcode %}

Note each conditional uses a condition.


---

# 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://x8ight.gitbook.io/syntask/limiters/conditionals/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.
