The Iterator design pattern provides a solution:
Encapsulate the access and traversal of an aggregate in a separate Iterator object.
Clients request an Iterator object from an aggregate (createIterator())
and use it to access and traverse the aggregate.
Describing the Iterator design in more detail is the theme of the following sections.
See Applicability section for all problems Iterator can solve.

Background Information