The
when program control statement executes a statement based on the value of one or more other variables, combining
if statements with the power of
recode. The statement is similar to statements in other programming languages (like
switch in C or
when in Kotlin).
One or more expressions,
expression1 to
expressionN, are given, with each expression separated by two colons
::. These expressions must evaluate to either a number or string. Based on the values of each expression, CSPro evaluates each line between the
when and
endwhen, trying to match a line's values,
value1 to
valueN, with the evaluated expressions. Once a line matches, a statement, which is given after the arrow
->, is executed and program control moves to statements following the
endwhen. Only a single statement can be provided per line.
Each value provided must evaluate to the same type (number or string) as its respective expression. A value omitted is considered a match, and if no values are provided, then the optional else_statement is executed (assuming no preceding line matched).