> For the complete documentation index, see [llms.txt](https://craftscript.kenzie.mx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://craftscript.kenzie.mx/tutorials/getting-started/condition-keywords.md).

# Condition Keywords

Keywords that allow execution based on a condition.

There are 3 **condition** keywords. These run a statement based on a condition.

Condition statements are designed to be followed by a block section.

#### If

If statements run a statement if and only if a check passes.

```java
if %check% %then%
```

```java
if 5 == 5 /print hello

result = true
if result {
    /print hello
}

if "hello" == "hello" /print hello
```

If statements will **conform** the check result to a boolean (true/false) value.

| True                 | False         |
| -------------------- | ------------- |
| `true`               | `false`       |
| Any non-zero number. | A zero value. |
| Any non-null object. | `null`        |

This means that statements like the following are valid and correct.

```java
if "hello" /print ok
if 1 /print ok
if true /print ok
```

#### While

While statements run a statement **as long as** a check passes.

{% hint style="danger" %}
Unless something changes to make the check false, a while statement will run forever.
{% endhint %}

```java
while %check% %then%
```

```java
var = 0
while var < 5 var = var + 1
while var > 0 var = var - 1
```

While statements will **conform** the check result to a boolean (true/false) value.

#### For

For statements run a statement once for every value in a collection of values.

{% hint style="info" %}
Although there is no explicit check, a `for` statement is a special `while` statement internally.

```java
while <values has next element> {
    var = <next element>
    ...
}
```

{% endhint %}

```java
for %variable% = %values% %then%
```

```java
for word = ["hello", "there"] /say {word}

for number = [1, 2, 3] {
    if number > 1 /say the number is {number}
}

for value = values {
    /print {value}
}
```

For statements are useful for iterating (looping) over a number of values.
