Conditional Statements (if
)
The if
statement in Femscript is used to execute code based on a condition. It provides a way to handle decision-making logic in your scripts. Unlike in some other languages, the condition
in Femscript is not just a boolean expression—it is a block of code. The value of the condition is determined by the result of the last operation in the block.
An optional else
block can be used to execute code when the condition evaluates to false
.
Syntax
Conditionals in Femscript use the following structure:
The condition
is a block enclosed in {}
that can contain multiple operations. The value of the condition is determined by the last operation inside the block.
Examples
Basic Example
In this example:
- The condition
{ age >= 18 }
evaluates tofalse
. - The
else
block is executed.
Complex Conditions
Condition can perform multiple operations:
Here:
- The
total
variable is calculated within the condition block. - The result of the block (
total > 10
) determines which branch of theif
statement is executed.