If statements are the first controls you will be exposed to. Controls allow you to, well, control the flow of your program. Specifically, if statements allow you to skip a specific block of code depending on whether a certain condition is met.

If statements are built around a conditional statement. At their core, conditional statements ultimately evaluate to either true or false: 1 or 0, respectively. You achieve that true or false state by constructing a simple test using comparison operators. There are 8 major comparison operators in C++: greater than (>), less than (<), equal to (==), not equal to (!=), less than or equal to (<=), greater than or equal to (>=), and (&&), and or (|| -- [shift + ]). We'll start with the first four, whose uses are fairly obvious. Simply place a number or initialized variable on either side of these symbols, and the computer will interpret the code as 1 if it is true or 0 if it is false. The following is an if statement with a real condition in it.

if(3 < 5)
{}

You'll notice that if statements are extremely easy. They are nothing more than the word "if", a conditional statement enclosed in parentheses, and whatever code you want to execute in the event that the conditional statement evaluates to true enclosed in brackets. Since 3 is, in fact, less than 5, the code in the brackets would execute in this example. And yes, the brackets are conspicuously empty for no reason in particular. Lastly, you'll note that the if statement in and of itself contains no semicolon. Only the code inside the brackets will contain them.

We'll now examine the "and" and "or" operators. These simply combine two or more conditional statement into one big one; the "and" operator requires that both statements evaluate to true, and the "or" operator requires that one of the statements be true. Examples ensue!

int c = 2;

if(3 < 5 && c == 2)
{
  c++;
}

if(c < 5 || c > 10)
{
  cout << "Variable c is not between 5 and 10!
";
}

As you can see, the two operators are fairly phonetic in their use. I've only one piece of advice. Their usage can very quickly become confusing as you try to construct specific conditions, so be careful. A fine example is trying to test if a variable is within a certain range as I did in the second if statement. Even with a solid grasp and a great deal of use, constructing such conditional statements will almost always be a little more complicated than they seem at first, so test thoroughly. If you hadn't guessed, the first statement evaluates to true because 3 is less than 5 AND c equals 2, and the second statement also evaluates to true because c is less than 5. C is not greater than 10, but since the two tests were joined with the or operator, only one needs to be true.

Finally, there is the negation operator (that is my term, not an official one). This simply reverses the result of a conditional statement. So if it evaluated to true, the negation operator changes the result to false. It is used by placing an exclamation point in front of the statement you want to negate, as such:

if(!(3 < 5))
{}

So, the compiler tests to see if 3 is less than 5, which it is, and then it negates the result, returning false.