nested if..else
as this results in more complications and the developer gets confused. Hence, CPP Switch statements usage is the best option in such cases.
Although most CPP 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
".
"Ternary Operator"
. expression1
is true, then the compiler executes expression2
, otherwise executes expression3
. Here, three operands are used at a time.