Datasheet

16
Part I: Let’s Get Started
6. Move wrench to lug nut.
7. While (lug nut attached to car)
8. {
9. Turn wrench counterclockwise one turn.
10. }
11. }
12. }
13. Move wrench to toolbox.
14. Release wrench.
This program begins just as before with the grabbing of a wrench from the
toolbox. Beginning with Step 2, however, the program loops through Step 12
for each lug nut bolt on the wheel.
Notice how Steps 7 through 10 are still repeated for each wheel. This is
known as a nested loop. Steps 7 through 10 are called the inner loop, while
Steps 2 through 12 are the outer loop.
The complete program consists of the addition of similar implementations of
each of the steps in the algorithm.
Computer processors
Removing the wheel from a car seems like such a simple task, and yet it takes
11 instructions in a language designed specifically for tire changing just to
get the lug nuts off. Once completed, this program is likely to include over 60
or 70 steps with numerous loops. Even more if you add in logic to check for
error conditions like stripped or missing lug nuts.
Think of how many instructions have to be executed just to do something as
mundane as move a window about on the display screen (remember that a
typical screen may have 1280 x 1024 or a little over a million pixels or more
displayed). Fortunately, though stupid, a computer processor is very fast.
For example, the processor that’s in your PC can likely execute several billion
instructions per second. The instructions in your generic processor don’t do
very much — it takes several instructions just to move one pixel — but when
you can rip through a billion or so at a time, scrolling a mere million pixels
becomes child’s play.
05_617977-ch01.indd 1605_617977-ch01.indd 16 7/6/10 11:38 PM7/6/10 11:38 PM