Trees
So we've looked at using iterators to simplify runtime behaviour, and to simplify interfaces. This works well, because the Iterator interface is well known, we use it a lot, and so it's a familiar thing.
But not all containers are straight forward lists, and not every traversal is linear. We might have other data structures we need to traverse, like this lovely tree.
Does it make sense to do for each in tree? Not in the general case, no, there is no right way.
For this tree here, there are three different ways: preorder; postorder; in-order; which yield three different results. Often tree walking is handled in a recursive manner.
[[Java's TreeSet and TreeMap are not trees. They are Sets/Maps which use trees internally.]]