# 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.

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


---

# 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://osl.mistium.com/program-flow/switch-case.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.
