- Switch statement is an alternative to if else ladder statement which allows us to execute multiple operations for different values.
- We can define various statement in multiple cases for different values of single variable.
Rules for switch statement
- Switch expression should be an integer or character data type.
- Case value must be an integer or constant value.
- We can use only case value inside the switch statement.
- Break statement is not mandatory in switch. It is optional.
- If a program does not find a break statement in switch expression, all the cases in the switch will be executed along with the matched case.
Syntax for switch statement
Flow chart for switch
Sample Program
Output