---
title: "switch — Selective execution"
description: "iXML command switch: Selective execution."
canonical_url: "https://www.zeyos.com/ixml/ref/switch"
markdown_url: "https://www.zeyos.com/ai/guide/ixml/ref/switch.md"
section: "ixml-reference"
authority: "reference"
language: "en"
source_repository: "https://cloud.zeyos.com/__doc/ixmldoc.xml"
source_sha256: "a23f04e6a98628ca3c273c3b8dd2c33c034cfda3e0f00478d8793074fd2f70dd"
---

# switch — Selective execution

The SWITCH construct is a control flow structure that allows for selective execution of code controlled via a multiway branch. It can be thought of as a series of IF constructs, each with the same value to compare from.

If the value of a SWITCH statement equals the value of an embedded CASE statement, the control flow continues with the execution of that CASE statement. Otherwise, the control flow continues with the execution of the embedded DEFAULT statement.

### Attributes
| Name | Type | Default | Description |
| ---- | ---- | ------- | ----------- |
| value | string |  | Value to compare from |

### Children
- case (occurrence: multiple) — Branch execution
- default (occurrence: single) — Default execution

### Parents
- (not restricted in the reference)

### Result
- (none documented)

### Examples

```xml
<set var="lastname">Gates</set>

<switch value="$lastname">
	<case value="Gates">
		<output>My name might be Bill Gates!</output>
	</case>

	<case value="Jobs">
		<output>My name might be Steve Jobs!</output>
	</case>

	<default>
		<output>My name is not Bill Gates nor Steve Jobs!</output>
	</default>
</switch>

<!-- My name might be Bill Gates! -->
```

```xml
<set var="firstname">Steve</set>
<set var="lastname">Gates</set>

<switch value="$lastname">
	<case value="Gates">
		<if value1="$firstname" func="=" value2="Steve">
			<next/>
		</if>

		<output>My name might be Bill Gates!</output>
	</case>

	<case value="Jobs">
		<output>My name might be Steve Jobs!</output>
	</case>
</switch>

<!-- My name might be Steve Jobs! -->
```
