To set conditions that control the flow of the program.
The block of statements are executed in a sequential order, and enclosed within curly braces (optional)
If the test condition within the if is true then the Code block within curly braces are executed in a sequential order.
If the condition within the if expression is evaluated as false, then the code block within the else part is executed.
If the first if is evaluated as true, then the code block within it is executed. Or else, the following if else conditions are evaluated and if found true, the code block within it get executed.
How does a switch Statement Works?
1. The value of the switch expression is evaluated once in the beginning
2. This switch expression value is then matched against the expressions, called as labels following the keyword case
3. If switch condition is satisfied by any of the cases , then the code block within that case is executed.
4. If none of the cases are matched then the control drops to the default case.
Here , the break statement is used to terminate the program if any of the case satisfies the condition, if omitted then all the cases are matched
If you need a case statement to fall through, do not use the break for that particular case.