When is if-else-if statement preferred over switch statement?
Answers
Answered by
1
A switch statement is usually more efficient than a set of nested ifs. Deciding whether to use if-then-else statements or aswitch statement is based on readability and the expression that the statement is testing. ... Prefer switch if the number of cases are more than 5 otherwise, you may use if-else too.Key Differences Between if-else and switch. Expression inside if statement decide whether to execute the statements inside if block or under elseblock. On the other hand, expression inside switch statement decide which case to execute. ... On the other hand, switch statement evaluates only character or a integer datatype.
Answered by
0
Following are the reason where if-else-if statement preferred over switch statement is given below.
Explanation:
- When we have to check multiple condition then switch is better choice but when we have 2 0R 3 condition then if /else is better way to implement them.
- if we have to find the boolean value then if / else will implement this however switch will never do this because it works on the static value
- An switch provides highly readability as compared to the if /else statements because missing an else block to search is ,more difficult as compared to switch.
Learn More:
- brainly.in/question/3735157
Similar questions