|
|
|
|
|
|
|
Figure 5-1
Sequential Control |
|
|
|
|
|
|
|
|
We use a selection (or branching) control structure when we want the computer to choose between alternative actions. We make an assertion, a claim that is either true or false. If the assertion is true, the computer executes one statement. If it is false, it executes another (see Figure 5-2). The computer's ability to solve practical problems is a product of its ability to make decisions and execute different sequences of instructions. |
|
|
|
|
|
|
|
|
The Payroll program in Chapter 1 shows the selection process at work. The computer must decide whether or not a worker has earned overtime pay. It does this by testing the assertion that the person has worked more than 40 hours. If the assertion is true, the computer follows the instructions |
|
|
|
|
|
|
|
|
Figure 5-2
Selection (Branching) Control Structure |
|
|
|
|
|