The "if"
expression is called a conditional statement (decision
statement) because it tests a relationship by using the relational
operators. Based upon the result of the comparison, decisions are made
as to which statement(s) the program will execute next.
if (test
condition)
{
block of one;
or more C++ statements;
} |
 |
If you put a
semicolon after the test condition, the "if" statement
will STOP. The block will not be executed. |
The test condition can be any
relational comparison (or logically TRUE) statement and must be enclosed in
parentheses. The block of statements is enclosed in braces and
indented for readability. The braces are NOT required if only ONE
statement follows the "if", but it is a good idea to include them.
The block executes only if the test
condition is TRUE. If the test condition is FALSE, the block is
ignored and execution continues to the next statement following the block.
|