switch break c++ code example

Example 1: c++ switch case statement

switch (n)
{
    case 1: // code to be executed if n = 1;
        break;
    case 2: // code to be executed if n = 2;
        break;
    default: // code to be executed if n doesn't match any cases
}

Example 2: switch statement c++

switch(expression) {
   case constant-expression  :
      statement(s);
      break; //optional
   case constant-expression  :
      statement(s);
      break; //optional
  
   // you can have any number of case statements.
   default : //Optional
      statement(s);
}

Example 3: c++ awitch statements

var = 1

switch (var):

  case 1:
	break; // Code that is executed if var is 1

  case 2:
	break; // Code that is executed if var is 2

  default:
	break; // Code that is executed if no cases match