N - Number of conditions
can be checked in parallel. Each and every condition can be called as a block
.If any conditions is matched in the Nth
condition, then the controller will execute the respective block of statements.
Here in Switch statement, each and every conditional block will end with break
. Using the break tag one can stop the controller from automatic executions of the next block.
Although most Switch statements can be rewrited with if statements, it tends to be easier for the compiler to optimize a large Switch statement than a long chain of if statements. break
" is the keyword used to end the case statements.
First, the expression is compared with case 1, if case 1 meets the criteria, then the corresponding statements gets executed until the break is reached. Otherwise (If it does not satisfy the condition then) switch goes to next case and the process continues. If neither case is satisfied then switch executes statements of "default case
".