Problem Solving using C Language

0 of 77 lessons complete (0%)

Conditional Statement

switch Statements

 Switch case statements are a substitute for long if statements that compare a variable to several integral values

 The switch statement is a multiway branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression.

 Switch is a control statement that allows a value to change control of execution.

Example

int main() 
{ 
   int x = 2; 
   switch (x) 
   { 
       case 1: printf("Choice is 1"); 
               break; 
       case 2: printf("Choice is 2"); 
                break; 
       case 3: printf("Choice is 3"); 
               break; 
       default: printf("Choice other than 1, 2 and 3"); 
                break;   
   } 
   return 0; 
}