HomeManualTopicsTypesSymbols

std::case

a multiway conditional expression or statement

Parameters

expr
the first argument
values_and_bodies*
an alternating sequence of case-values and statement sequences

Result

results
whatever the selected function returns

Description

The first argument is a value that is compared to the values of the following arguments.

The arguments are an alternating sequence of values and functions (statement sequences).

The values are compared to the first argument in the order they appear.

If a value matches the first argument, the corresponding function is called.

If no value matches the first argument, the last function (if any) is called.

Example

$chr 'H' case chr 'a' .. 'z': println! "lower case character" 'A' .. 'Z': println! "upper case character" '_': println! "underscore" '0' .. '9': println! "digit" : println! "neither character nor digit nor underscore"

Output

upper case character

Topic

Branches

See also

std::if classic if; can be used as a function or a procedure
std::cond a multiway conditional expression or statement