title: About iteration count for recursive function
body: <p>I am trying to write out the bisection function (<a href="https://en.wikipedia.org/wiki/Bisection_method" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Bisection_method</a>) as asked in the HW, and I want to count the iteration number.</p>
  <p>Here's the code:</p>
  <pre><code>itera = 0
  bisect &lt;- function(f, lower, upper, tol)
  {
    mid &lt;- (lower + upper)/2
    if(abs(f(mid)) &lt; tol){
      output &lt;- list(root = mid, f.root = f(mid), iter = itera, estim.prec = abs(f(mid)))
      return(output)
    }
    else{
      itera = itera + 1
      if(f(mid) * f(lower) &lt; 0){
        
        bisect(f, lower, mid, tol)
      }
      else{
        
        bisect(f, mid, upper, tol)
      }
    }
  }
  f &lt;- function(x) {x^3 - 2*x - 1}
  bisect(f,1,2,10^(-6))
  </code></pre>
  <p>My test function is <code>x^3 - 2*x - 1</code>, and the output:</p>
  <p><a href="https://i.stack.imgur.com/ZNTq0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZNTq0.png" alt="enter image description here" /></a></p>
  <p>shows the iteration number is 0, I don't know how can I debug it.</p>