Switch statement is nothing but a multiple elseif statement with high level of readability. See the following example
switch (x)
{
case 1:
// statement 1
break;
case 2:
// statement 2
break;
case 3:
// statement 3
break;
default:
// statement 4
break;
}
Equivalent If-else-if statement
if(x==1)
{
// statement 1
}
else if(x==2)
{
// statement 2
}
else if(x==3)
{
// statement 3
}
else
{
// statement 4
}
Now coming to switch statement, switch statement i.e. multiple elseif statement should be avoided as it is processing intensive there are better ways t handle i.e. array of pointers and based on array index call specific processing.