When should I use if/else if/else statements? When should I use switch statements?


#1

Question

When should I use if/else if/else statements? When should I use switch statements?

Answer

Consider using switch statements when you have more simple, albeit many cases/conditions, and/or your conditions to check are fixed values. Consider using if/else if/else statements when your logic requires more complex conditions to check and/or when the conditions to check will evaluate to a boolean.