+1 vote
166 views
in C program by (3.4k points)
edited

When is a switch statement can be better than an if statement?

1 Answer

0 votes
by (3.4k points)
selected by
 
Best answer
If you have more than one condition to check on single variable or a single expression, then switch is better than if. In switch statement, program’s execution jumps to the matching value if found. If you use if condition, it checks one by one condition. So it is highly recommended to use switch, if you have to check a variable/condition/expression with multiple values.

Related questions

0 votes
1 answer 142 views
0 votes
1 answer 158 views
+1 vote
1 answer 136 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

563 users

...