If is better than switch due to following cause

 If is better than switch due to following cause :



if-else statement can evaluate almost all the types of data such as integer, floating-point, character, pointer, or Boolean while A switch statement can evaluate either an integer or a character

2. In the case of 'if-else' statement, either the 'if' block or the 'else' block will be executed based on the condition while the switch statement contains multiple cases or choices. The user will decide the case, which is to execute

3. If-else checks both equality and logical expressions while switch checks only equality expression

4. If the condition is not true, then by default, else block will be executed while in switch If the value does not match with any case, then default statement is executed.

Comments