November 2002
Beginner
432 pages
11h 44m
English
C supports an if...else statement that works a lot like the Visual Basic If...Else statement. Table 13.5 lists the relational operators with which you can compare data.
| Relational Operator | Description |
|---|---|
| == | Equal to |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
| <= | Less than or equal to |
| != | Not equal to |
Use braces to group the body of an if statement as shown in the following statement:
if (age < 18)
{ printf("You cannot vote yet\n");
yrs = 18 - age;
printf('You can vote in %d years.\n", yrs);
}
else
{
printf("You can vote.\n");
}
The individual statements in the if statement end with semicolons, but not the if. The if...else spans several lines, so you don't put semicolons after the ...
Read now
Unlock full access