If, or Else If?

The difference between these related actions

If Statements

If statements are their own entity. One if statement can stand all by its lonesome and still do exactly what it is told. they will be tested whether the if statement before it was true or not. The only time that if statements have a prior condition are if they're nested inside another if statement.

Else If Statements

Else if statements are the more needy counterpart of the if statement. While If statements can go alone, an else if needs a previous statement to check before it runs. For example an if statement followed by two else statements will only run through all three if the if and first else if statement are both false. If either of them were true, then the second else if would never run. If they were all if statements, however, then all three would run on their own accord no matter the result of the others.

Some examples

if(i == 0) ... //if i =0 this will work and skip following statement

else if(i == 1) ...//if i not equal to 0 and if i =1 this will work and skip following statement

else if(i == 2) ...// if i not equal to 0 and 1 and if i==2 the statement will execute



if(i == 0) ...//if i =0 this will work and check the following conditions also

if(i == 1) ...//regardless of i == 0 check, this if condition is checked

if(i == 2) ...//regardless of i == 0 and i == 2 check ,this if condition is checked

Big image