01. Difference between if and switch
The if
statement has a condition part that can:
Take any integer or boolean value
If integer is non zero or boolean is true
Execute the true block
else
Execute the false block
The switch
statement can take an expression that evaluates to an integer or enumeration.
It matches the value of the expression with cases
When match is found
the lines after that case is executed.
The if
statement can take any kind of boolean expression while the switch statement can only take integer expressions that maps for equality.
Last updated