
294 CHAPTER 6 Flow of Control,Part 2: Looping
To see a step-by-step illustration of a while loop with a sentinel value,look for the Flash movie in the
Chapter 6 folder on the CD-ROM included with this book.Click on the link for Chapter 6 to start the
movie.
CODE IN ACTION
It is important to choose the sentinel value carefully. Obviously, the sen-
tinel value cannot be a value that the user might want to be processed. In
the addition calculator, we want to allow the user to enter positive or nega-
tive integers. We chose 0 as the sentinel value for two reasons. First, adding
0 to a total has no effect, so it is unlikely that the user will want to ente ...