If / else
if cond then { ... } else { ... } runs one of two blocks. if cond then a else b chooses one of two values. There is no ternary operator.
if-else.lithe
(* `if` with blocks is a statement. Chain conditions with `else if`. *)
storage is record {
size : uint;
}
external function recordSize(const x : uint) is {
if x < 10 then {
storage.size := 1;
} else if x < 100 then {
storage.size := 2;
} else {
storage.size := 3;
}
}
(* `if` with values is an expression. Both branches are required and share a type. *)
external pure function min(const a : uint; const b : uint) : uint is
if a < b then a else b
external pure function classify(const x : uint) : uint is {
const size : uint := if x < 10 then 1 else if x < 100 then 2 else 3;
} with size- An
ifexpression can go anywhere a value can, like acase: a function body, awithresult, aconstinitializer, or an operand. - A branch can be
fail E, as acasearm can:if amount > 0 then amount else fail Zero. - Inside each branch the compiler knows whether the condition held, so
if a >= b then a - b else 0has no underflow check.

