At some point in learning to program, you will have to have fun with IF statements or selection methods. This includes, but not limited to Switch, IF and so on. Understanding them is fundamental to learning to program.
Understanding the IF
At some point your program will need to make a choice to where it should go and what code to run depending on a condition. So we can create a small C++ program that uses a simple If statement.
#include <iostream>
using namespace std;
int main()
{
int age = 23;
if(age < 18)
{
cout << "You're under age!";
}
system("PAUSE");
return 0;
}
So we have created a simple condition. The condition used within the ( ) of the If statement is as follows:
IF AGE IS LESS THAN 18 THEN SAY YOU’RE UNDER AGE
It does help to try and visualize how IF statements look and one way to do that would be as shown below.

The diamond shape represents a decision that has to be made by the program, it can either go straight down or to the right. So the value stored in the variable age determines how the program will flow. Sometimes however, you want your program to make a choice between certain conditions. So say we wanted to display a website content depending on age. So if they are over a certain age, the website will display something different.
int main()
{
int age = 23;
if(age > 40)
{
//DISPLAY OVER 40 CONTENT
}
else
{
//DISPLAY CONTENT FOR ANYONE 40 OR UNDER
}
system("PAUSE");
return 0;
}
So we have introduced the ELSE, this means that if the IF statement condition fails it will move down and run the else (the else does not have a condition, but only runs if all else fails).

An if statement can be very long and you can also use something called else if as shown below.
int main()
{
int age = 23;
if(age > 40)
{
//DISPLAY OVER 40 CONTENT
}
else if(age < 10)
{
//DISPLAY UNDER 10 CONTENT
}
else
{
//DISPLAY CONTENT FOR ANYONE 40 OR UNDER
}
system("PAUSE");
return 0;
}
Now this Else if can be pictured as below:

So you can see that the else if will only be reached if the first IF is not true. If the first one is true, then the else if is not reached. However, if you where to get rid of the else from in front of the else if. Then we would have a different result. The two if statements could be considered separate, rather than one block of statements.
int main()
{
int age = 23;
if(age > 40)
{
//DISPLAY OVER 40 CONTENT
}
if(age < 10)
{
//DISPLAY UNDER 10 CONTENT
}
else
{
//DISPLAY CONTENT FOR ANYONE 40 OR UNDER
}
system("PAUSE");
return 0;
}

So the else belongs to the if(age < 10) block and not the if(age > 40). So we have two separate statement blocks.