# IF

**IF** __Expression__ [ { **AND IF** | **OR IF** } __Expression__ ... ] [ **THEN** ]
...
[ **ELSE IF** __Expression__ [ { **AND IF** | **OR IF** } __Expression__ ... ] [ **THEN** ]
... ]
[ **ELSE**
... ]
**ENDIF**

**IF** __Expression__ [ { **AND IF** | **OR IF** } __Expression__ ... ] **THEN** ...

Since 3.4

**IF** __Expression__ [ { **AND IF** | **OR IF** } __Expression__ ... ] **THEN** ... **ELSE** ...

Conditional control structure.

### One-line syntax

You can write an IF ... THEN control structure on one line, provided that the true part of the conditional is written just after the THEN keyword.
In that case, the THEN keyword is mandatory.

Since Gambas 3.4, the `IF`

...`THEN`

...`ELSE`

... syntax written on the same line has been implemented.

### Short-circuit path

When you use several test expressions splitted by **AND IF**

keywords, then they are evaluated from left to right until the first FALSE one is found, and then the test is FALSE. If all expressions are TRUE, then the test is TRUE.

When you use several test expressions splitted by **OR IF**

keywords, then they are evaluated from left to right until the first TRUE one is found, and then the test is TRUE. If all expressions are FALSE, then the test is FALSE.

All that is different from using `AND`

or `OR`

that always evaluate its arguments.

You cannot mix **AND IF**

and **OR IF**

keywords on the same line.

### Examples

**Dim** k **As** **Integer**
**For** k **=** **1** **To** **10**
**If** k **<** **5** **Or** **If** k **>** **5** **Then**
**Print** k**;;**
**Else**
**Print**
**Print** "5 has been reached!"
**End** **If**
**Next**
**Print**

```
1 2 3 4
5 has been reached!
6 7 8 9 10
```

**If** **Pi** **>** **0** **Or** **If** **(****1** **/** **0****)** **>** **0** **Then** **Print** "Hello"
**If** **(****Pi** **>** **0****)** **Or** **((****1** **/** **0****)** **>** **0****)** **Then** **Print** "World!"
**Catch**
**Print** Error**.**Text

### See also