How to do sentinel logic
Here is the pattern: (note this is NOT code!)
input statement (inputting into a variable x)
while x is not the sentinel value
process x as needed
input statement (inputting into a variable x)
(yes, this is the same statement as the one outside of the loop!)
Summary
- input before the loop
- test at the top of the loop for the value
- do not read more into the spec than it says, "a -1" is NOT
the same thing as "anything negative"!
- process the data inside the loop - you know it is valid data
- at the very bottom of the loop do another input, just
like the one before the loop starts