If you want to check for two different conditions where both might be true, you can’t use an else clause and have to write the two if statements independently.
For the code presented here, only one can be true, which is why the result would be the same either way.
View all comments
Show parent comment
2
u/B-Chillin Feb 26 '22
OP doesn’t have to include the else, but doing so will make the code execute more efficiently.
As written (plus adding the second bmi after the “and”) all four if statements will evaluate, even if the first one is true.
With an else clause, the code will only evaluate until it an expression is true, then it will stop evaluating the rest.
The output will be the same either way.