Choose between many exact values without a long if chain.

In this video:

  • switch (value) { ... } compares one value with each case
  • case 1: runs when the value is 1
  • default: runs when no case matches
  • break; leaves the switch; without it, the code of the next cases runs too ("falls through")
  • Several cases written one after another share the same code