Code: Select all
let <variable> on <condition> is
<expression> [else <expression>];
end
The let-statement allows a variable to be tested against different conditions using multiple on-branches:
Code: Select all
let <variable>
on <condition> is
<expression>;
on <condition> is
<expression>;
on <condition> is
<expression> [else <expression>];
end
The let-statement differs from the if and when-statements in that it can only be used for assignment. It is the only statement with is .. end; blocks allowed inside do .. end; blocks.
Example:
Code: Select all
const is
hot = 1;
cold = 0;
frozen = -1;
red = "red";
blue = "blue";
white = "white";
end
dim water: int8 = cold;
dim color: str;
main do
let color
on water == frozen is
white;
on water == hot is
red else blue;
end
print(color);
end