I have a bit of code where doing elseif after an if is a different outcome than if I just do another if after the first if.
(Sorry if its a bit confusing).
So what I'm asking is when should I use:
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
else x==0
Note that there is no "else if". Your second example is equivalent to:
1 2 3 4 5 6 7
if ()
{}
else
{
if ()
{}
}
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.