Switch Case

switch is used to perform different actions based on different values of a variable.

int day = 3;
switch (day) {
  case 1:
    cout << "Monday";
    break;
  case 2:
    cout << "Tuesday";
    break;
  default:
    cout << "Other day";
}

Use break to exit a case. The default block is optional.

← PrevNext →