Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

What is a sentinel loop???

+4 votes
asked Feb 14, 2015 in (Winter 14) by Lauren Johnson (100 points)

1 Answer

0 votes
A sentinel loop is a special form of a while loop that uses a boolean condition called a sentinel. The loop runs until the sentinel is reached. In a sentinel loop a boolean statement needs to be initiated that states the condition that needs to be met for the loop to terminate. Inside the loop their needs to be a way to update the sentinel. An example of a sentinel loop would be a loop that runs until the user types "stop". Stop would be the sentinel and the code would be written so that the loop would run until the user types stop.
answered Feb 15, 2015 by Nowlan Savage (100 points)
Careful with vocabulary.  The "sentinel" is NOT the boolean condition itself.  The sentinel is the special symbol or token that means signals the end of input, so the sentinel is the word "stop" in your example above.  But I think you are describing a sentinel loop, which is a loop that keeps going until a sentinel gets inputted.  See page 325 in your textbook -- section 5.2 on fencepost loops and sentinel loops.