title: Iterating through a tree structure
body: <p>So suppose I have some kind of tree structure with nodes and children. I want to travel through the tree and shout when I see certain nodes.</p>
  
  <p>Look at the following, this is ActionScript but it's similar to Java etc:</p>
  
  <pre><code>for(var i:int=0; i&lt;parent.children.length; i++)
  { 
    child = parent.children[i];
    if(child.nodeName == "A")
    {
      parent = child;
      for(var j:int=0; j&lt;parent.children.length; j++) 
      {
        child = parent.children[j];
        if(child.nodeName == "B")
        {
          trace("B found");
          parent = child;
          //now search for C etc...
        }
      }
    }
  }
  </code></pre>
  
  <p>The problem comes with the 'parent = child' line, I want to "jump" into then next set of children, but of course when I go back up I've lost the reference to the parent above. What's the usual method of going about this?</p>