Skip to Content
Absolute Beginner's Guide to Programming, Third Edition
book

Absolute Beginner's Guide to Programming, Third Edition

by Greg Perry
November 2002
Beginner content levelBeginner
432 pages
11h 44m
English
Que
Content preview from Absolute Beginner's Guide to Programming, Third Edition

C Control Statements

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.

Table 13.5. C Relational Operators
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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Absolute Beginner's Guide to Programming, Second Edition

Absolute Beginner's Guide to Programming, Second Edition

Greg Perry

Publisher Resources

ISBN: 0789729059Purchase book