When to use else if
I have a bit of code where doing
is a different outcome than if I just do another
after the first
(Sorry if its a bit confusing).
So what I'm asking is when should I use:
and when should I use:
I really should know this but I don't
you use else if if you have another condition besides the if and the else so if you have 3 or more conditions than you use else if
ex: if x<0
else if x>0
Note that there is no "else if". Your second example is equivalent to:
When you do have two separate if-clauses, both are evaluated. When you do have if-else clause, the else-part is evaluated only when the original condition is false.
Topic archived. No new replies allowed.