12.1. Making Decisions

Learning Objectives:

We have discussed two major abilities that computers have. Computers can name values. Computers can repeat steps. The third major ability that a computer has is the ability to make decisions. We make decisions all the time. Before we leave the house we may check to see if it will rain that day, and if it will, we bring an umbrella.

Picture of an umbrella

Figure 1: An umbrella in the rain

Computers can also make decisions or take action when something is true. More specifically, (1) a computer can test data and (2) a computer can execute instructions if that test is true. The ability to test data and take actions on the result is what allows the computer to deal with input and take action on it (e.g., if the credit card is valid then charge the card), or deal with data from the world around (e.g., if I see a stop sign then stop.).

Picture of a stop sign

Figure 2: Picture of a stop sign

The computer’s ability to take action (execute some code) when something is true is also called conditional execution.

Note

Discuss topics in this section with classmates.

Show Comments
You have attempted of activities on this page