Here is a simple, somewhat
more concrete example taken from Design Patterns.For the List class there is an iterator
class called ListIterator, which knows about its list.It keeps track of an index, which gives the
current position in the list.It
returns the element at that index upon request and it knows when all elements
have been processed.The interface is
adequate for writing the loop.This is
an external iterator because the client code controls the traversal with
iterator.Next().