Cerberus X Documentation

Keyword If

Marks the start of a conditional If block.

Syntax

If expression [Then]
Statements...
Endif

If expression [Then]
Statements...
End If

If expression [Then]
Statements...
End

If expression [Then] Statements...

Description

If marks the start of a conditional block, whereby the statements within will be executed if expression is True. The keyword Then after the expression is optional.

An If block is closed by the Endif keyword, or, optionally, End If, or simply End.

There is also a single-line variant available, which does not use an Endif closing statement; the expression to be tested is followed by an optional Then keyword, then the statement(s) to be executed.

Program flow can be modified within an If block using Else and Elseif.

See also

Else | Elseif | Endif | End
Language reference

Examples

' Simple variable check:

If a = 1
Print "a equals one"
Endif

' Same, using End If instead of Endif:

If a = 1
Print "a equals one"
End If

' Same again, but using End:

If a = 1
Print "a equals one"
End

' Single-line example, using Then:

If a = 1 Then Print "a equals one"

' The 'Then' separator is optional:

If a = 1 Print "a equals one"