If, else and else if are all constructs that help fork out the code. Basically, you use them when you want to make a decision.
An example would be 'if it is sunny, I will go outside. Otherwise I will stay inside'
In code (ignoring unnecessary things)
if (sunny) { goOutside(); } else { stayInside(); }
You can use the else if statement if you want to add additional conditions. Extending the previous example: “if it is sunny, I will go outside. If it is stormy, I will go to the basement, otherwise I will stay inside”
In code
if (sunny) { goOutside(); } else if (stormy) { goDownstairs(); } else { stayInside(); }
EDIT Section:
Here's how you can write a few if and as and conditions. The following example can be written in at least two ways:
“If it's sunny and warm, go outside. If it's sunny and cold, don't do anything.”
if (sunny) { if (warm) { goOutside(); } else if (cold) { doNothing(); } }
OR
if (sunny && warm) { goOutside(); } else if (sunny && cold) { doNothing(); }
Malaxeur
source share