Sentinel values, or, Transversal Path terminators, in programming, are used as conditions of termination, usually in a loop or repeating algorithm. They do not hold or reference any data managed by the data structure, and thus, computation doesn’t encounter it as a legitimate processing output. In other words, a sentinel value is chosen typically as data values that the loop won’t meet, and hence not perform with.
When no. repetitions of a process are unknown before it structure starts
Trigger end to user input
Typically associated to file streams
Do While statements
Sentinel values can be used whence the number of repetitions required for a 'looping process' are unknown before the actual repetition structure begins, and also to signal the end of user input. Hence why algorithms which repeat until a sentinel value is seen are known as sentinel loops.They are also typically associated to file-streams.
Null character to show end of null-terminated string
Null pointer to show end of a linked list or tree
Non-negative integer to show end of non-negative integer strings
Can be used in programs where test scores are provided, and when a certain value is inputted, it may result in termination of the loop, and lead to the average being printed.
In that example, -1 as the s.v. is used as it is an algorithm which computes non-negative integers, and so such a value can be set as the sentinel value as it will never be encountered as a legitimate processing output, and this is basically that third example right there.
Chortle.ccsu.edu. (2018). Sentinel Values. [online] Available at: https://chortle.ccsu.edu/QBasic/chapter09/bc09_12.html [Accessed 18 Oct. 2018].
Users.cs.fiu.edu. (2018). Types of loops. [online] Available at: https://users.cs.fiu.edu/~downeyt/cop2210/loops.html [Accessed 18 Oct. 2018].
YouTube. (2018). What is SENTINEL VALUE? What does SENTINEL VALUE mean? SENTINEL VALUE meaning & explanation. [online] Available at: https://www.youtube.com/watch?v=dwk_QZiXBrg [Accessed 18 Oct. 2018].
Webopedia.com. (2018). What is sentinel value? Webopedia Definition. [online] Available at: https://www.webopedia.com/TERM/S/sentinel_value.html [Accessed 18 Oct. 2018].
character?, W. (2018). What's the difference between a Sentinel value and an End-of-file character?. [online] Stack Overflow. Available at: https://stackoverflow.com/questions/43731611/whats-the-difference-between-a-sentinel-value-and-an-end-of-file-character [Accessed 18 Oct. 2018].