When Developers need switch statements while programming?
When they are developing a project in which there is a need to select one option from multiple ones depending upon some variable value. They prefer Switch which is also known as a compound statement.
a) They can execute multiple statements
b) More convenient
c) Multi-way branch system
d) Use multiple cases
Real-time example illustrating use of Switch
Suppose there a situation occurs when there is a need to test a variable for fifty different values and to perform a specific task depending upon that test. In such case it is less efficient to use if-else statement because code appears more messy Thus, developer prefer switch case.
Flow Chart of a Switch Statement: