5 Decision and Control Statements

A computer is a powerful instrument because it can make decisions based on the data it receives. For example, a computer can turn on an LED if a button is being pressed and turn off the LED if it isn’t. In this chapter we will see how C’s various decision and control statements operate. Then we’ll apply them to embedded programming by making our device respond to button presses.

The if Statement

We use the if statement to execute some code only if some condition is true. Here is the general form of this statement:

if (condition)
    statement;

To conditionally execute more than one statement, enclose the set ...

Get Bare Metal C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.