The two are related, think of an elseif as an else with a condition. Taking the following example.
if ( x == 1 ) Code here is executed when x == 1elseif ( x == 2 ) Code here is executed when x is not 1 and x == 2else Code here is executed in all other cases. In other words x is not 1 and x is not 2endif
Some examples in English
If it is Tuesday we should go shopping
else if it is Wednesday we could go to the beach
Becomes
if ( day == Tuesday ) go shoppingelseif ( day == Wednesday ) go to the beachendif
In this case, we go shopping if it is a Tuesday and go to the beach if it is a Wednesday, but there is no case for any other day
If it is sunny we could go to the beach
else we will go shopping
if ( weather == sunny ) go to the beachelse go shoppingendif
In this case, if the weather is sunny we go to the beach and in all other cases we go shopping. The else will always happen if none of the conditaions in the if or elseif statments are satisfied.
else could also be considered the same as elseif ( 1 == 1 ). 1 is always equal to 1 so the code in the elseif block will always be executed if none of the above conditions are met.
Some other quick examples
if ( x == 1 )elseif ( x == 1 ) code here is never executed as there is already a condition that is satisfied above this oneelse code here is executed when x is not equal to 1endif
if ( x == 1 ) code here is executed when x == 1elseif ( y == 1 ) code here is executed when y == 1 and x != 1elseif ( z == 1 ) code here is executed when z == 1 and x != 1, y != 1else code here is executed when x != 1, y != 1 and z != 1.endif