<s>
In	O
computer	B-General_Concept
programming	I-General_Concept
,	O
a	O
sentinel	B-Data_Structure
value	I-Data_Structure
(	O
also	O
referred	O
to	O
as	O
a	O
flag	B-Data_Structure
value	I-Data_Structure
,	O
trip	O
value	O
,	O
rogue	B-Data_Structure
value	I-Data_Structure
,	O
signal	B-Data_Structure
value	I-Data_Structure
,	O
or	O
dummy	O
data	O
)	O
is	O
a	O
special	O
value	O
in	O
the	O
context	O
of	O
an	O
algorithm	O
which	O
uses	O
its	O
presence	O
as	O
a	O
condition	O
of	O
termination	O
,	O
typically	O
in	O
a	O
loop	O
or	O
recursive	O
algorithm	O
.	O
</s>
<s>
The	O
sentinel	B-Data_Structure
value	I-Data_Structure
is	O
a	O
form	O
of	O
in-band	O
data	O
that	O
makes	O
it	O
possible	O
to	O
detect	O
the	O
end	O
of	O
the	O
data	O
when	O
no	O
out-of-band	B-Protocol
data	I-Protocol
(	O
such	O
as	O
an	O
explicit	O
size	O
indication	O
)	O
is	O
provided	O
.	O
</s>
<s>
A	O
sentinel	B-Data_Structure
value	I-Data_Structure
is	O
sometimes	O
known	O
as	O
an	O
"	O
Elephant	O
in	O
Cairo	O
,	O
"	O
due	O
to	O
a	O
joke	O
where	O
this	O
is	O
used	O
as	O
a	O
physical	O
sentinel	O
.	O
</s>
<s>
In	O
safe	O
languages	O
,	O
most	O
sentinel	B-Data_Structure
values	I-Data_Structure
could	O
be	O
replaced	O
with	O
option	O
types	O
,	O
which	O
enforce	O
explicit	O
handling	O
of	O
the	O
exceptional	O
case	O
.	O
</s>
<s>
Some	O
examples	O
of	O
common	O
sentinel	B-Data_Structure
values	I-Data_Structure
and	O
their	O
uses	O
:	O
</s>
<s>
Null	O
pointer	O
for	O
indicating	O
the	O
end	O
of	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
or	O
a	O
tree	B-Application
.	O
</s>
<s>
This	O
latter	O
test	O
is	O
what	O
is	O
avoided	O
by	O
using	O
a	O
sentinel	B-Data_Structure
value	I-Data_Structure
.	O
</s>
<s>
Assuming	O
the	O
array	O
can	O
be	O
extended	O
by	O
one	O
element	O
(	O
without	O
memory	O
allocation	O
or	O
cleanup	O
;	O
this	O
is	O
more	O
realistic	O
for	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
as	O
below	O
)	O
,	O
this	O
can	O
be	O
rewritten	O
as	O
:	O
</s>
<s>
The	O
test	O
for	O
i	O
<	O
len	O
is	O
still	O
present	O
,	O
but	O
it	O
has	O
been	O
moved	O
outside	O
the	O
loop	O
,	O
which	O
now	O
contains	O
only	O
a	O
single	O
test	O
(	O
for	O
the	O
value	O
)	O
,	O
and	O
is	O
guaranteed	O
to	O
terminate	O
due	O
to	O
the	O
sentinel	B-Data_Structure
value	I-Data_Structure
.	O
</s>
<s>
There	O
is	O
a	O
single	O
check	O
on	O
termination	O
if	O
the	O
sentinel	B-Data_Structure
value	I-Data_Structure
has	O
been	O
hit	O
,	O
which	O
replaces	O
a	O
test	O
for	O
each	O
iteration	O
.	O
</s>
