The sentinel value

Sometimes, the loop doesn’t have a fixed number of repetitions. Instead, an indicator value stops the loop. This special value is called the sentinel value. For example, we don’t know how much data is in a file without reading it all. However, we know that every file ends with an end-of-file (EOF) mark. So, the EOF mark is the sentinel value in this case.

Note: We should select a sentinel value that’s not expected in the normal input.

Get hands-on with 1400+ tech skills courses.