traverse a tree by iteration