Branching in Leo differs from traditional programming languages. Leo developers should keep in mind that every program compiles to a circuit which represents all possible evaluations.
A conditional (ternary) expression takes three operands.
- A condition that evaluates to a boolean followed by a question mark
- A first expression to execute if the condition is true followed by a colon
- A second expression to execute if the condition is false followed by a semicolon
Ternary expressions are the cheapest form of conditional.
The boolean condition in an
if statement does not require parenthesis. The statements to execute require brackets
else if clauses can be used to chain
for loops with bounded iteration.
to_number must be constant numbers.
For more information on branching patterns in Leo see Common Patterns.