# Switch

**Switch statement** compares a variable with one or many given values and executes a block of code associated with this value when a match is found. Starting from v4.0, Sanny Builder supports it for all games.

### Syntax

<pre class="language-pascal"><code class="lang-pascal"><strong>switch &#x3C;var>
</strong>   case &#x3C;n1>, &#x3C;n2>, ... &#x3C;n3>
     // do something if &#x3C;var> is equal to n1, n2, or n3
   case &#x3C;n4>
     // do something if &#x3C;var> is equal to n4
   default
     // do something if none of the values above matched the variable
end
</code></pre>

`<var>` a global or local [variable](https://docs.sannybuilder.com/language/data-types/variables). Can be an integer, float, or string variable.\
`<n>` - a comma-separated list of values the variable is compared with. Sanny uses `==` [operator](https://docs.sannybuilder.com/language/instructions/expressions) to compare values. `n` can be an integer number, float, string, also a [constant](https://docs.sannybuilder.com/language/data-types/constants).

{% hint style="info" %}
Each case can be associated with up to `8` values.
{% endhint %}

Default case is optional and can be omitted. When provided, default must be the last in the list of cases.

Switch statement does not support any extra instructions outside of `case` or `default` blocks. It also does not support a "fall through" behavior usually found in C-like languages. When the case block ends, the control flow is transferred out of the switch statement.

#### Example

<pre class="language-pascal"><code class="lang-pascal"><strong>switch 0@
</strong>   case 1, 2, 3
     0ace: "Value is 1, 2, or 3"
   case 5
     0ace: "Value is 5"
   default
     0ace: "Value is not 1, 2, 3, or 5"
end
</code></pre>
