Switch Statement : When we have most than one valid choice or condition then, most programming languages provide another selection concept known as multiway selection. Multiway selection chooses among several alternatives. C ++ has two different ways to implement multiway selection:
ii. else-if statement
Switch Statement :
This is applicable when we have more than one valid choices to choose from then we can use switch statement instead of if statement.
cout<<“Enter number1 operator number2 : “;
cout<<“Sum : “<<(a+b)<<endl;
cout<<“Difference : “<<(b-a)<<endl;
cout<<“Sum : “<<(a*b)<<endl;
cout<<“Difference : “<<(b/a)<<endl;
Enter number1 operator number2
Sum : 5
Note : Here break is a jump statement and break is used to get out of that condition or that case.
Default is used as else statement if any of the condition doesn’t satisfy then default case will be called. So we have to use default statement in case.