# Switch Statement

> Checks one value against a list of cases and runs the one that matches.

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** Switch Case, Match Statement, Case Statement

## Think of it like

It is like a sorting machine for coins. Each coin size drops into its own slot.

## Definition

A switch statement checks one value against a list of cases and runs the matching one. It does the job of a long chain of if and else lines, but is easier to read. A default case runs when nothing matches. In C and JavaScript, each case needs a break, or the next case runs too. Python 3.10 added a match statement that does the same job.

## Example

A game reads the key pressed. The switch runs one case for up, one for down and a default for any other key.

## Example code

```javascript
switch (day) {
  case "Sat":
  case "Sun":
    console.log("Weekend");
    break;
  default:
    console.log("School day");
}
```

Two cases share one answer. Every other day falls to default.

## Why it matters

Many choices hang on one value, like a menu pick or a status. A switch lays them out in one clear list.

## Common mistake

Leaving out break in C or JavaScript. The code then falls through and runs the next case as well.

## Three principles

- **One value.** Checked against many cases.
- **Default case.** Catches anything not listed.
- **Mind fall-through.** Some languages need break.

## Related terms

- [Conditional Statement](https://learn.benibix.com/term/development/conditional-statement)
- [Control Flow](https://learn.benibix.com/term/development/control-flow)
- [Break Statement](https://learn.benibix.com/term/development/break-statement)
- [Enumeration (Enum)](https://learn.benibix.com/term/development/enum)
- [JavaScript](https://learn.benibix.com/term/development/javascript)

## Taught in

- [If, Else and Match](https://learn.benibix.com/learn/development-concepts/if-else-and-match): Programming Basics, 10/18

![One value, a day name, enters at the top and meets four doors in a row: case Saturday, case Sunday, case Monday and a default door. An arrow shows the value Sunday going through only the Sunday door.](https://learn.benibix.com/diagrams/dev7-switch-statement.svg)

---

Source: https://learn.benibix.com/term/development/switch-statement
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
