Switch statements

suggest change

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.

A switch statement is often more concise and understandable than if...else if... else.. statements when testing multiple possible values for a single variable.

Syntax is as follows

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

there are sevaral things that have to consider while using the switch statement

Example can be given with the grades wise

char grade = 'B';

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents