title: Using enumerate function in while loops
body: <p>I have several mathematical algorithms that use iteration to search for the right answer. Here is one example:</p>
  
  <pre><code>def Bolzano(fonction, a, b, tol=0.000001):
      while abs(b - a) &gt; tol:
          m = (a + b) / 2
          if sign(fonction(m)) == sign(fonction(a)):
              a = m
          else:
              b = m
      return a, b
  </code></pre>
  
  <p>I want to count how many times the algorithm goes through the loop to get <em>a</em> and <em>b</em>. However this is not a <code>for</code> function and it isn't a list, so I can't clearly indicate what objects do I want to count if I use <code>enumerate</code>. Is there a way to count those loops?</p>
  
  <p>Note: I am not trying to change the code itself. I am really searching for a way to count iterations in a <code>while</code> loop, which I can then use for other cases.</p>