• Reference Guide

Conditional Evaluation

if(cond) block1
if(cond) block1 else block2
cond ? block1
cond ? block1 : block2
The condition (the parameter cond) must be of the Bool type. If the condition is satisfied (returns TRUE), block1 is evaluated, and its result is returned as the result of the entire conditional expression. Otherwise (if the condition returns FALSE), block2 is evaluated. If block2 is not specified, the conditional expression returns the NONE value.
The variant with ?: is provided for similarity to the languages like C and Java. In Enki, the both forms are equivalent – the both return a value. The only difference is in operator precedence.
As semicolon serves as a separator in Enki, the branch block1 must not be terminated with a semicolon.
The expressions block1 and block2 are blocks in the sense that the scope of variables defined within them is limited to the block.
Example 1:
a = 1;
a = 2;
Example 2:
var Int a = if(x>0) 1 else 2

See Also