title: Iteratively traverse through tree to find size
body: <p>I need to find the number of elements in a tree using an iterative algorithm, but I'm finding the code conceptually very difficult to write.</p>
  
  <p>My approach is to start at the root node and visit the child nodes, then the children of these child nodes, and so on.</p>
  
  <p>This is the code I've written which works for a small tree, but isn't a real solution because I'd need to add an additional block for each level of depth:</p>
  
  <pre><code>// Start the counter at 1 because the root node counts
  int size = 1;
  
  for(ITree child1 : root) {
      size++;
      for(ITree child2 : child1) {
          size++;
          for(ITree child3 : child2) {
              size++;
              for(ITree child4 : child3) {
                  size++;
                  for(ITree child5 : child4) {
                      size++;
                  }
              }
          }
      }
  }
  return size;
  </code></pre>