Please send questions to
st10@humboldt.edu .
* reminder of basic while loop syntax and semantics;
* reminder of basic count-controlled loop pattern;
* then, worked on a lab exercise: spicy_count.cpp
(a main function with a count-controlled loop that calls
spiciness_level a number of times specified by the user...)
BUT -- not everything is a count-controlled loop...
* another common "pattern"
sentinel-controlled loop
...used when the user is to enter values "until they're ready to stop",
and they can indicate by a special value -- called the sentinel --
that they want to stop;
...so, in the logic, you need to ask, about each entered value,
IS it "real" data, or is it time to quit?
* the pattern you end up with is:
...see your flow chart in your notes!
* also made a PDF after class; see
basic-sentinel-flow-chart.pdf
read the FIRST piece of data before the loop,
while the data IS really data
{
act on that data
get the next piece of data
}
* one big decision with a sentinel-controlled loop:
...what can the sentinel value be?
(has to be RECOGNIZABLE and reasonable as not-data;)
...the q to end your Purpose statement in funct_play2
is an example of a "clunky" sentinel;
* spicy_sentinel.cpp
which will keep asking for Scoville ratings
until the user enters a NEGATIVE Scoville rating
as the sentinel, to indicate they want to go...
STYLE POINT: a sentinel controlled loop's prompts
should WARN the user what to do to quit!