Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 420
yihangho Avatar asked Feb 01 '10 12:02

yihangho


People also ask

What is a sentinel in a while loop?

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); }

What is a sentinel loop?

A sentinel loop is a short segment of adynamic ileus close to an intra-abdominal inflammatory process. When seen, it is usually identified on abdominal radiography. The sentinel loop sign may aid in localizing the source of inflammation.


2 Answers

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);
}
like image 177
MSalters Avatar answered Oct 11 '22 12:10

MSalters


A sentinel is a special value, e.g. boolean value, extremely big or small. It is used to determine when to stop the loop.

A good example is in the implementation of merge sort, e.g. read page 4 of http://www.cs.princeton.edu/courses/archive/spr07/cos226/lectures/04MergeQuick.pdf.

like image 38
Yin Zhu Avatar answered Oct 11 '22 11:10

Yin Zhu