Java Theory
Switch Statement
The switch statement means it executes one statement from multiple conditions.
- The switch declaration is evaluated once.
- The value of the expression is compared to the value of each case.
- If there is a match the value of case, then the block of code to be executed.

Break Statement
Break statement is used to control the flow of the execution, the expression is satisfied the execution moves out the switch case block.
Syntax of Switch |
---|
switch(x) { Case 1: //code to be executed if x=1; break; Case 2: //code to be executed if x=2; break; Case n: //code to be executed if x=n; break; default: //code to be executed if x doesn't match any case; break; } |