# switch

### Description

With `switch`, you can list a set of values that can be assigned to an [expression](https://docs.atfinity.io/rule-language/expressions). Which expression gets used as output, is determined by how you write the `switch`-expression.

The expression has to close with the keyword `end`.

This operator is most often used in [calculated information](https://docs.atfinity.io/rule-language/conditional-expressions/broken-reference).

### Syntax

```
switch [expression]
  when [value_1] then [expression_1]
  ...
  when [value_n] then [expression_n]
  else [expression]
end
```

* 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 `else` is used.

### Example

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
switch p.domicile
  when ch then local_customer
  when de then german_customer
  else world_customer
end
```

If the domicile of the [instance](https://docs.atfinity.io/guides/glossary/instance) is provided as Germany, the output will mark the instance as german\_customer. If the domicile is South Africa, then `else` is used: the instance would be ‘world\_customer’.
