# Conditional Statements

Conditional statements control conditional branching. The body of a conditional statement is only executed if the value of the expression is nonzero.

## If Statement

### Syntax <a href="#syntax" id="syntax"></a>

*`if-statement`*:\
 **`if (`** *`expression`* **`)`** [*`statement`*](https://glados-2.gitbook.io/clight/reference/statements)\
 **`if (`** *`expression`* **`)`** [*`statement`*](https://glados-2.gitbook.io/clight/reference/statements) **`else`** [*`statement`*](https://glados-2.gitbook.io/clight/reference/statements)

### Example

```c
int a = 1;
if (a < 0) {
    a = 0;
} else {
    a++;
}
```

In this example, if `a` is a negative number, its value is set to zero. Otherwise, the value of `a` is increased by 1.

You can also have nested branching, like so:

<pre class="language-c"><code class="lang-c"><strong>int a = 0;
</strong><strong>int b = 0;
</strong><strong>if (a > 0) {
</strong>    if (b > a) {
        a = b;
    }
} else {
    b = a;
}
</code></pre>

Or concurrent if statements:

```c
int a = 1;
if (a < 0) {
    a = -1;
} else if (a > 1) {
    a = 1;
} else {
    a = 0;
}
```
