When to use else if

I have a bit of code where doing else if 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:
1
2
3
4
if()
{}
if()
{}

and when should I use:
1
2
3
4
if()
{}
else if()
{}

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
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.
Topic archived. No new replies allowed.