title: How to stop recursion after returning from method
body: <p>I have a program which makes call to a functin which is recursive.</p>
  <pre><code>int dd=dis(root,2,0);
  </code></pre>
  <p>Function code</p>
  <pre><code>   public int dis(Node n,int g,int count)
     {
      if(g==n.data)
      {
          System.out.println(&quot;equal count&quot;+count);
          return count;
      }
      
      else if(g&gt;n.data)
      {
          count=count+1;
          dis(n.right,g,count);
      }
      
      else if(g&lt;n.data)
      {   
          count=count+1;
          dis(n.left,g,count);
      }
      System.out.println(&quot;function&quot;+count);
      return count;
  }
  </code></pre>
  <p>When the data equals node value, the function returns count, the exact value I needed. However, the recursion continues after count is returned, and returns the abnormal count value at the end of function.</p>
  <p>I want to totally back out of the function after count is returned from == case, I dont want recursion to modify the value in the calling function after first count has been returned.</p>