Velo by Example: If/Else

Branching in Velo uses if-then-else syntax. Conditionals are expressions — they return values.

The simplest form is an inline expression with then and else.

int a = 5;
str result = if a == 2 then "two" else "not two";

You can use block form with curly braces for multi-line branches.

int a = 5;
str result = if a == 2 then {
    "two"
} else {
    "not two"
};

Chain else if for multiple conditions. Since if is an expression, the result can be assigned directly.

int score = 85;
str grade = if score >= 90 then {
    "A"
} else if score >= 80 then {
    "B"
} else if score >= 70 then {
    "C"
} else {
    "F"
};

There is no ternary operator — use inline if-then-else instead.

int max = if a > b then a else b;