switch(a) //a is int
{
case 6:
statements;
break;
case 10:
statements;
break;
case 7:
statements;
break;
default:
statements;
break;
}
* Default clause is optional.
* Default clause can be given any where in switch block
switch(a) //a is int
{
case 6:
statements;
case 10:
statements;
case 7:
statements;
break;
default:
statements;
break;
}
* If required number of cases can be given together
switch(a) //a is int
{
case 12:
case 2:
case 10:
statements;
break;
case 7:
case 19:
statements;
break;
default:
statements;
break;
}
for characters
switch(a)// a is single char
{
case ‘A’:
case ‘a’:
statements;
break;
case ‘D’:
case ‘d’:
statements;
break;
case ‘e’:
case ‘E’:
statements;
break;
default:
statements;
break;
}