The switch case statement is also used for making decision, unlike the if else statement , we can not test conditions like "greater than" or "less than" . in switch case we can test the value of a variable and decide what to do if a particular value is stored in the variable.
the syntax for switch statement below
switch(varable to test)
{
case value 1 :
statements if value 1 stored in the variable;
break;
case value 2 :
statements if value 2 stored in the variable;
break;
*
*
default:
statements if none of the values match;
break;
}
example
the user will enter a weekday number( 1 to 7 ) and the program will display the name of the corresponding day
the syntax for switch statement below
switch(varable to test)
{
case value 1 :
statements if value 1 stored in the variable;
break;
case value 2 :
statements if value 2 stored in the variable;
break;
*
*
default:
statements if none of the values match;
break;
}
example
the user will enter a weekday number( 1 to 7 ) and the program will display the name of the corresponding day