# switch

### Description

With `switch`, you can list a set of values that can be assigned to an [expression](/rule-language/expressions.md). 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](broken://pages/-ML71u0p4UUNJ6GTeFl0).

### 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](/guides/glossary/instance.md) 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’.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.atfinity.io/rule-language/conditional-expressions/switch-expression.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
