
314 CHAPTER 6 Flow of Control,Part 2: Looping
6.6 Constructing Loop Conditions
Constructing the correct loop condition may seem a little counterintuitive.
The loop executes as long as the loop condition evaluates to true. Thus, if
we want our loop to terminate when we read the sentinel value, then the
loop condition should check that the input value is not the sentinel value.
In other words, the loop continuation condition is the inverse of the loop
termination condition. For a simple sentinel-controlled loop, the condition
normally follows this pattern:
while ( inputValue != sentinel )
In fact, you can see that the loop conditions in many of the examples ...