Syntax:
- switch(expression)
- {
- case constant-exp1 : statements; break;
- case constant-exp2: statements; break;
- default: statements;
- }
In switch case, the break statement is used to terminate the switch case. Basically it is used to execute the statements of a single case statement. If no break appears, the flow of control will fall through all the subsequent cases until a break is reached or the closing curly brace ‘}’ is reached.
In above , switch case don't have break statement ,
1. If inChar='A' , flow control will execute all statements after Case A: till switch case end (in case any break states occurs between statement , it will terminated at the point but in above example we don't have any break statement, so whole switch block will execute).
Output : Choice A
Choice B No Choice
In case if inChar='C' then output will be Choice B No Choice.
it's not necessary that we should always add break statement for each cases in switch, including break statement in switch case is based on our requirement.
Answer is C