Magma provides a case-statement and a case-expression for multi-branching conditionals.
The case-expression is a conditional expression. It causes execution of some statements to depend on the value of a certain expression.
The syntax of the case-expression is:
case< EXPRESSION | EXPRleft : EXPRright, EXPRleft : EXPRright, ..., EXPRleft : EXPRright, default : EXPRdflt >
The section `default : EXPRdflt' must come at the end. The newlines shown above are not required, merely provided for clarity.
To execute the case-expression, Magma evaluates EXPRESSION. Magma then evaluates each EXPRleft until it finds an expression whose value is equal to that of the EXPRESSION. If such an expression is found then the value of the case-expression is the value of EXPRright immediately to the right of the colon following EXPRleft. If none of the EXPRleft have the same value as EXPRESSION, then the value of the case-expression is the value of EXPRdflt immediately to the right of the colon following `default'.
> greeting := case< Random(1, 3) | > 1 : "Hello.", > 2 : "G'day.", > default : "Pleased to meet you." >; > print greeting; G'day.
[Next] [Prev] [Right] [____] [Up] [Index] [Root]