switch, you can list a set of values that can be assigned to an expression. Which expression gets used as output, is determined by how you write the
The expression has to close with the keyword
when [value_1] then [expression_1]
when [value_n] then [expression_n]
- All values will be compared against the result of the expression
- All expressions need to return the same type of output, e.g. a number.
- If none of the defined values apply, the expression following
A Zurich-based institution is mostly active in its home market and in Germany. It groups its customers in three categories, based on where they live.
Swiss customers get labeled as local. German customers get the label German. The relatively small number of customers from other countries get grouped together in a ‘world’ category.
p is Person
when ch then local_customer
when de then german_customer
If the domicile of the instance is provided as Germany, the output will mark the instance as german_customer. If the domicile is South Africa, then
elseis used: the instance would be ‘world_customer’.