yihangho yihangho - 1 month ago 17
C++ Question

Sentinel while loop for C++

Can anyone tell me what is sentinel while loop in C++? Please give me an example using sentinel while loop.

Answer

A "sentinel" in this context is a special value used to indicate the end of a sequence. The most common sentinel is \0 at the end of strings. A "sentinel while loop" would typically have the form:

while (Get(input) != Sentinel) {
  Process(input);
}