Skip to content

SWITCH Expression

SWITCH selects one result from multiple cases.

Syntax

SWITCH{input;case1;result1;case2;result2;...;default}

ACE resolves input exactly once. It then resolves case expressions in order until it finds the first match. The matching result is selected; if no case matches, the final default value is selected.

After resolution, ACE first attempts numeric equality (std::stod on both values). If numeric conversion is not possible, it falls back to exact string equality.

Example

SWITCH{25;10;A;25;B;17;C;D}

Result:

B

Evaluation behavior

SWITCH is lazy for result branches: only the selected result (or the default when no case matches) is resolved. Non-selected result branches are not evaluated, so a CMD{...} that exists only in an unselected result branch is not executed.

Case expressions are not result branches. They are resolved as ACE tests them in order. A side-effecting expression placed in the switch input or in a case expression can therefore run when that input/case is evaluated.

An empty selected result is normalized to 0. A switch input that contains a CMD or another expression is still evaluated only once.