<s>
In	O
object-oriented	B-Language
programming	I-Language
,	O
the	O
iterator	B-Language
pattern	I-Language
is	O
a	O
design	O
pattern	O
in	O
which	O
an	O
iterator	O
is	O
used	O
to	O
traverse	O
a	O
container	B-Application
and	O
access	O
the	O
container	B-Application
's	O
elements	O
.	O
</s>
<s>
The	O
iterator	B-Language
pattern	I-Language
decouples	O
algorithms	O
from	O
containers	B-Application
;	O
in	O
some	O
cases	O
,	O
algorithms	O
are	O
necessarily	O
container-specific	O
and	O
thus	O
cannot	O
be	O
decoupled	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
hypothetical	O
algorithm	O
SearchForElement	O
can	O
be	O
implemented	O
generally	O
using	O
a	O
specified	O
type	O
of	O
iterator	O
rather	O
than	O
implementing	O
it	O
as	O
a	O
container-specific	O
algorithm	O
.	O
</s>
<s>
This	O
allows	O
SearchForElement	O
to	O
be	O
used	O
on	O
any	O
container	B-Application
that	O
supports	O
the	O
required	O
type	O
of	O
iterator	O
.	O
</s>
<s>
that	O
describe	O
how	O
to	O
solve	O
recurring	O
design	O
problems	O
to	O
design	O
flexible	O
and	O
reusable	O
object-oriented	B-Language
software	O
,	O
that	O
is	O
,	O
objects	O
that	O
are	O
easier	O
to	O
implement	O
,	O
change	O
,	O
test	O
,	O
and	O
reuse	O
.	O
</s>
<s>
See	O
also	O
the	O
UML	B-Language
class	O
and	O
sequence	O
diagram	O
below	O
.	O
</s>
<s>
The	O
essence	O
of	O
the	O
Iterator	B-Language
Pattern	I-Language
is	O
to	O
"	O
Provide	O
a	O
way	O
to	O
access	O
the	O
elements	O
of	O
an	O
aggregate	O
object	O
sequentially	O
without	O
exposing	O
its	O
underlying	O
representation	O
.	O
</s>
<s>
In	O
the	O
above	O
UML	B-Language
class	O
diagram	O
,	O
the	O
Client	O
class	O
refers	O
(	O
1	O
)	O
to	O
the	O
Aggregate	O
interface	O
for	O
creating	O
an	O
Iterator	O
object	O
(createIterator( )	O
)	O
and	O
(	O
2	O
)	O
to	O
the	O
Iterator	O
interface	O
for	O
traversing	O
an	O
Aggregate	O
object	O
(next( )	O
,	O
hasNext( )	O
)	O
.	O
</s>
<s>
C++	B-Language
and	O
Python	B-Language
are	O
notable	O
examples	O
.	O
</s>
<s>
.NET	B-Application
Framework	I-Application
has	O
special	O
interfaces	O
that	O
support	O
a	O
simple	O
iteration	O
:	O
System.Collections.IEnumerator	O
over	O
a	O
non-generic	O
collection	O
and	O
System.Collections.Generic.IEnumeratorxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
over	O
a	O
generic	O
collection	O
.	O
</s>
<s>
C#	B-Application
statement	O
foreach	O
is	O
designed	O
to	O
easily	O
iterate	O
through	O
the	O
collection	O
that	O
implements	O
System.Collections.IEnumerator	O
and/or	O
System.Collections.Generic.IEnumeratorxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
interface	O
.	O
</s>
<s>
C++	B-Language
implements	O
iterators	O
with	O
the	O
semantics	O
of	O
pointers	O
in	O
that	O
language	O
.	O
</s>
<s>
In	O
C++	B-Language
,	O
a	O
class	O
can	O
overload	O
all	O
of	O
the	O
pointer	O
operations	O
,	O
so	O
an	O
iterator	O
can	O
be	O
implemented	O
that	O
acts	O
more	O
or	O
less	O
like	O
a	O
pointer	O
,	O
complete	O
with	O
dereference	O
,	O
increment	O
,	O
and	O
decrement	O
.	O
</s>
<s>
This	O
has	O
the	O
advantage	O
that	O
C++	B-Language
algorithms	O
such	O
as	O
std::sort	O
can	O
immediately	O
be	O
applied	O
to	O
plain	O
old	O
memory	O
buffers	O
,	O
and	O
that	O
there	O
is	O
no	O
new	O
syntax	O
to	O
learn	O
.	O
</s>
<s>
In	O
C++	B-Language
language	I-Language
,	O
we	O
say	O
that	O
an	O
iterator	O
models	O
the	O
iterator	O
concept	B-Application
.	O
</s>
<s>
The	O
interface	O
from	O
the	O
Java	B-Language
collections	I-Language
framework	I-Language
extends	O
Iterable	O
.	O
</s>
<s>
JavaScript	B-Language
,	O
as	O
part	O
of	O
ECMAScript	O
6	O
,	O
supports	O
the	O
iterator	B-Language
pattern	I-Language
with	O
any	O
object	O
that	O
provides	O
a	O
next( )	O
method	O
,	O
which	O
returns	O
an	O
object	O
with	O
two	O
specific	O
properties	O
:	O
done	O
and	O
value	O
.	O
</s>
<s>
Some	O
of	O
JavaScript	B-Language
's	O
built-in	O
types	O
such	O
as	O
Array	O
,	O
Map	O
,	O
or	O
Set	O
already	O
define	O
their	O
own	O
iteration	O
behavior	O
.	O
</s>
<s>
PHP	B-Application
supports	O
the	O
iterator	B-Language
pattern	I-Language
via	O
the	O
Iterator	O
interface	O
,	O
as	O
part	O
of	O
the	O
standard	O
distribution	O
.	O
</s>
<s>
Example	O
of	O
patterns	O
using	O
PHP	B-Application
:	O
</s>
<s>
Python	B-Language
prescribes	O
a	O
syntax	O
for	O
iterators	O
as	O
part	O
of	O
the	O
language	O
itself	O
,	O
so	O
that	O
language	O
keywords	O
such	O
as	O
for	O
work	O
with	O
what	O
Python	B-Language
calls	O
iterables	O
.	O
</s>
<s>
In	O
Python	B-Language
3	O
,	O
next( )	O
was	O
renamed	O
__next__( )	O
.	O
</s>
<s>
Raku	B-Application
provides	O
APIs	O
for	O
iterators	O
,	O
as	O
part	O
of	O
the	O
language	O
itself	O
,	O
for	O
objects	O
that	O
can	O
be	O
iterated	O
with	O
for	O
and	O
related	O
iteration	O
constructs	O
,	O
like	O
assignment	O
to	O
a	O
Positional	O
variable	O
.	O
</s>
<s>
Here	O
's	O
an	O
example	O
of	O
a	O
range	O
subroutine	O
that	O
mimics	O
Python	B-Language
's	O
range	O
function	O
:	O
</s>
