Apart from code readability, why is it bad to use lots of if statements?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have a lot of if statements one after the other, then a switch case statement is more useful. At least it has a fixed response time for each possible inupt as it does not need to fall through all the if statements.
A lot of if (and else) statement usually indicates
a) Violation of Single responsibility Principle
b) Need to refactor out into Strategy Design Pattern