if/else Statement¶
The if/else statement executes a block of code if a specified condition is true
.
If the condition is false
, another block of code can be executed.
Use comparison & logical operators to create a condition that's either true
or false
In ScarLang we have the following conditional statements:
- Use
if
to specify a block of code to be executed, if a specified condition istrue
- Use
else
to specify a block of code to be executed, if the same condition isfalse
- Use
else if
to specify a new condition to test, if the first condition isfalse
Syntax¶
The if
statement specifies a block of code to be executed if a condition is true
:
1 2 3 |
|
The else statement specifies a block of code to be executed if the condition is false
:
1 2 3 4 5 |
|
The else if statement specifies a new condition if the first condition is false
:
1 2 3 4 5 6 7 |
|
Single line if statement¶
There is also a single line version of the if statement.
It is not possible to use else
and else if
with this single line if statement.
1 |
|