In safe languages, most sentinel values could be replaced with option types, which enforce explicit handling of the exceptional case.
Unlike the above uses, this is not how the data is naturally stored or processed, but is instead an optimization, compared to the straightforward algorithm that checks for termination.
For example, if searching for a value in an array in C, a straightforward implementation is as follows; note the use of a negative number (invalid index) to solve the semipredicate problem of returning "no result": However, this does two tests at each iteration of the loop: whether the value has been found and whether the end of the array has been reached.
Assuming the array can be extended by one element (without memory allocation or cleanup; this is more realistic for a linked list, as below), this can be rewritten as: The test for i < len is still present, but it has been moved outside the loop, which now contains only a single test (for the value), and is guaranteed to terminate due to the sentinel value.
There is a single check on termination if the sentinel value has been hit, which replaces a test for each iteration.