sentinel
A special value that cannot occur in the real data and signals the end of it, such as an empty line ending a list of entries.
In more detail
A sentinel loop reads a value, checks it against the sentinel, and only then processes it, so the sentinel itself is never treated as data. It works however many items the user enters.
Example
line = input("Next: ")
while line != "":
items.append(line)
line = input("Next: ")Related terms
- while loop — A loop that keeps repeating its block as long as a condition stays true, checking the condition before each pass.
- input() — The built-in function that shows a prompt, waits for the user to type a line and press Enter, and returns what they typed as a string.
Taught in
- Interactive While Loops — Hands-on Python: Complete Video Course & Book
- Graphical Applications With While — Hands-on Python: Complete Video Course & Book
- Chapter Three In One Sitting — Hands-on Python: Complete Video Course & Book