Conditions
A conditional statement allows to evaluate one or more conditional instructions. Depending on the result, a block of code can be either executed or skipped. Conditional statements can be found in nearly all programming languages. It is an important part of the control flow.
Single Condition
A conditional statement starts with an IF keyword and ends with an END keyword.
Syntax
<condition>
- a conditional instruction. This instruction turns the condition result into either true
or false.
<consequent>
- a branch of the code that executes if the condition result is true
.
<alternative>
- an optional branch of the code that executes if the condition result is false
. If else
is omitted the flow skips the consequent
branch and continues after a closing end
keyword.
Example
Depending on the result of the is_player_playing
instruction, one or another message will be displayed.
Multiple Conditions (AND)
if and
allows to combine up to 8
conditional instructions and execute a block of code if all of them are true
.
Syntax
<consequent>
- a branch of the code that executes if all conditions are true
.
<alternative>
- an optional branch of the code that executes if any condition is false
. If else
is omitted the flow skips the consequent
branch and continues after a closing end
keyword.
Short-circuit evaluation is not supported. All conditions are evaluated regardless of the result of the preceding checks.
Example
Checking if a number is within the given range:
Multiple Conditions (OR)
if or
allows to combine up to 8
conditional instructions and execute a block of code if at least one of them is true
.
Syntax
<consequent>
- a branch of the code that executes if any condition is true
.
<alternative>
- an optional branch of the code that executes if all conditions are false
. If else
is omitted the flow skips the consequent
branch and continues after a closing end
keyword.
Short-circuit evaluation is not supported. All conditions are evaluated regardless of the result of the preceding checks.
Example
Checking if the vehicle model matches one of the given choices:
Last updated