title: For my C code, I am not sure how the binary tree is looping because my expected output is different then the actual output?
body: <p>I am tracing part of a code given by the professor but I don't understand how the binary tree is working. The question is: "Write a function to find the lowest common ancestor in a binary search tree and return a pointer. Lowest common ancestor between two nodes a and b in tree T is defined as
  the lowest node in T that has both a and b as descendants.
  Consider the following tree as an example. the lowest common ancestor of 4 and 8 is 6. lowest common ancestor of 4 and 14 is 10."</p>
  
  <pre><code>        10
       6     14
     4  8  12  16 
  </code></pre>
  
  <p>My question is I don't understand how it is looping?</p>
  
  <pre><code>node *lca(node *ptr, int a, int b)
  {
      if(ptr==NULL)
          return NULL;
      while (ptr != NULL)
      {   
          if (ptr-&gt;key &gt;= a &amp;&amp; ptr-&gt;key &lt;= b)//What's key?
              return (ptr);
          else if (ptr-&gt;key &gt; b)
              ptr = ptr-&gt;left;
          else if (ptr-&gt;key &lt; a)
              ptr = ptr-&gt;right;
      }
      return (ptr);
  }
  </code></pre>