HP C A.06.05 Reference Manual

Statements
if
Chapter 6 169
if
Syntax
if (
exp
) /* format 1 */
statement
if (
exp
) /* format 2 */
statement1
else
statement2
Arguments
exp
Any expression.
statement
Any null statement, simple statement, or compound statement. A statement
can itself be another if statement. Remember, a statement ends with a
semicolon.
Description
The if statement tests one or more conditions and executes one or more statements according
to the outcome of the tests. The if and switch statements are the two conditional branching
statements in C.
In the first form, if
exp
evaluates to true (any nonzero value), C executes
statement
.If
exp
is
false (evaluates to 0), C falls through to the next line in the program.
In the second form, if
exp
evaluates to true, C executes
statement1
, but if
exp
is false,
statement2
is performed.
A statement can be an if or if…else statement.
Example 1
You can test multiple conditions with a command that looks like this:
if (exp1) /* multiple conditions */
statement1
else if (exp2)
statement2