Compare if else with the switch statement

4.B) Compare if..else with the switch statement

Answer:-

IF-ELSESWITCH
Which statement will be executed depending upon the output of the expression inside the if statement?Which statement will be executed is decided by user.
the if-else statement uses multiple statements for multiple choices.switch statement uses a single expression for multiple choices.
if-else statement test for equality as well as for logical expression.switch statement test only for equality.
if statement evaluates integer, character, pointer or floating-point type, or boolean type.the switch statement evaluates only a character or integer value.
Either if the statement will be executed or else the statement is executed.the switch statement executes one case after another till a break statement appears or the end of the switch statement is reached.
If the condition inside if statement is false, then by default the else statement is executed if created.If the condition inside switch statements does not match with any of the cases, for that instance the default statement is executed if created.
It is difficult to edit the if-else statement if the nested if-else statement is used.It is easy to edit switch cases as they are recognized easily.

Leave a Reply

Your email address will not be published. Required fields are marked *