Conditional Statements
If-else statements allow you to decide between different branches in the code execution.
If-Else
Here is an example for such a conditional statement that simply checks a value. Note that elseif is additionally used to check the value again within the statement, which allows you to define another branch to be executed.
if(val>0.0)
echo("value is greater than zero")
elseif(val==0.0)
echo("value is zero")
else
echo("value is less than zero")
endif
An example condition can be anything that returns true or false, e.g.
if( a.getX() < b.getX() )
echo("x-coordinate of a is smaller than the one of b")
endif
Switch
An alternative to the if-statement for integral types (i.e. integer and unsigned) and strings is the switch-case-statement. It is of good use if the value to be checked is known to be in a specific set of possible values.
In case you have more branches, you can use the switch keyword where val in the following snippet needs to have the type FUnsigned, FInteger, FString or FEnum:
unsigned val(0)
// ...
switch(val)
case 1
echo("value is one")
case 2
echo("value is two")
default
echo("value is neither one nor two")
endswitch
Based on the value of the switched expression one of the case branches is chosen. If none of the cases matches the expression's value, the (optional) default branch is executed. If a case branch should be valid for multiple possible values, they can be comma separated:
switch(val)
case 1,2
echo("value is either one or two")
endswitch