> For the complete documentation index, see [llms.txt](https://osl.mistium.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://osl.mistium.com/program-flow/switch-case.md).

# Switch Case

Switch case is incredibly useful in osl due to its sheer speed when compared with an if else tree, along with its improved readability

## Main Syntax

You encapsulate a switch case statement with a simple switch statement

```javascript
switch value (

)
```

## Cases

You can add a simple case using the syntax shown below

```javascript
/* open the switch statement */
switch value (
  case value
    command
    break
  case value2
    /* a case :3 */
    break
)
```

## Default

You can use the default case to handle when none of the cases are met.

Like a normal case, its body may be inline or enclosed in parentheses.

It must be placed at the bottom of the switch case statement

Example shown below

```javascript
/* open the switch statement */
switch value (
  case value
    command
    break
  case value2
    /* a case :3 */
    break
  default
    /* any input that is not expected */
    break
)
```

## Break?

You need to end your cases with break otherwise you may end up causing some big issues

When break is run, the switch case will immediately be exited
