0
What is different between if else ladder and switch condition?
7 odpowiedzi
+ 4
In the condition of if statement, you can put an expression and compare it, or you can compare values, or you can use logical operators to combine two or more conditions into one.
On the other hand you cannot do this in the switch statement. You can just put the variable in the condition of switch statement and make cases for that particular variable.
0
answers frndz...
0
The syntax 😅
In my opinion switch statements improve the readability of code.
However some languages like python don't even have a switch command.
Maybe depending on the task the one or the other might also be faster, but just a guess.
0
I think it can depend on the language, but generally if/else is more flexible. You can have complex Boolean expressions in them, which isn't suitable for switch statements. A switch will compare on a value or enumerated type, but you could compare multiple types and conditions in if/else, so the readability can somewhat depend on the use case.
0
with "if" you can achieve the same results as with switch, but it can be useful in some cases. I recomend reading this post, where the post creator asked for practical use of switch statements
https://www.sololearn.com/discuss/1476353/?ref=app
0
but both have major differences
0
if else can take any data type for conditions but switch support all data type except double,float