> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# switch

> Execute different instructions based on a variable's value.

Execute different instructions based on a variable's value

## **Properties**

An object that accepts the following properties.

Name of the variable whose value needs to be compared.

[`Case_params`](#case_params) object of key-mapped values to array of [SWML Methods](/docs/swml/reference) to execute.

Array of [SWML Methods](/docs/swml/reference) to execute if no cases match.

### case\_params

The `case_params` object serves as a dictionary where each key is a string identifier, and
the associated value is an array of SWML Method objects.

Name of the variable whose value needs to be compared.

## **Examples**

```yaml
version: 1.0.0
sections:
  main:
    - switch:
        variable: call.type
        case:
          sip:
            - play:
                url: "say: You're calling from SIP."
          phone:
            - play:
                url: "say: You're calling from phone."
        default:
          - play:
              url: 'say: Unexpected error'
```

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "switch": {
          "variable": "call.type",
          "case": {
            "sip": [
              {
                "play": {
                  "url": "say: You're calling from SIP."
                }
              }
            ],
            "phone": [
              {
                "play": {
                  "url": "say: You're calling from phone."
                }
              }
            ]
          },
          "default": [
            {
              "play": {
                "url": "say: Unexpected error"
              }
            }
          ]
        }
      }
    ]
  }
}
```

```yaml
version: 1.0.0
sections:
  main:
    - set:
        foo: 5
    - execute:
        dest: example_fn
        params:
          foo: '${foo}'
  example_fn:
    - switch:
        variable: params.foo
        default:
          - play:
              url: 'say: nothing matches'
        case:
          '5':
            - play:
                url: 'say: yup, math works!'
```

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "set": {
          "foo": 5
        }
      },
      {
        "execute": {
          "dest": "example_fn",
          "params": {
            "foo": "${foo}"
          }
        }
      }
    ],
    "example_fn": [
      {
        "switch": {
          "variable": "params.foo",
          "default": [
            {
              "play": {
                "url": "say: nothing matches"
              }
            }
          ],
          "case": {
            "5": [
              {
                "play": {
                  "url": "say: yup, math works!"
                }
              }
            ]
          }
        }
      }
    ]
  }
}
```

## **See Also**

* **[Variables and Expressions](/docs/swml/reference/variables)**: Complete reference for SWML variables, scopes, and using variables in conditional logic
* **[cond](/docs/swml/reference/calling/cond)**: Alternative conditional logic method