Computer Science, asked by Incredible29, 1 year ago

Mention any TWO situations where the switch statement is preferable over the if-else statement .

Answers

Answered by sharmaakanksha27604
5

Hi everyone ,

If you have conditions where values are fixed or you have options like 1,2,3,4 and so on. for example program for automated complaint services where options are there and you have to choose any one according to your problems. In such situations using SWITCH statement in the program is the best.


Incredible29: thnx
Answered by kartikeyshu10
8
when you want to check few (mainly one condition) then If is better then switch statement. But if you need to check multiple conditions then a switch statement is far more efficient then If.

As per the Time Complexity (which means how much time an algorithm will take to complete it’s action) a switch is better but again in multiple condition situation.

One more thing about these two…..

In switch you can compare any data type (type of data.. int, string, bool).

But in the case of If statement, as it is a conditional statement it compare and on the basis of boolean value of the expression it result.

if(expression){printf(“If is executed”);}else{printf(“Else is executed”)}

In the above example expression could be comparison of any data type….

Hope this would help you
please mark it as brainliest

Anonymous: Nope
Anonymous: It's not right!
Anonymous: The correct would be one is to handle less complex than other
Anonymous: Like switch is for multiple condition
Similar questions