C++ switch statement

Switch statements in C++ allow you to select one of many code blocks to be executed. The syntax of a switch statement is as follows:

switch (expression) {
  case constant1:
    // code block
    break;
  case constant2:
    // code block
    break;
  // ...
  default:
    // code block
}

The expression is evaluated once and its value is compared with the values of each case constant. If a match is found, the code block following that case is executed. The break statement is used to exit the switch statement. If no match is found, the default code block is executed.