title: Using two conditions to write a conditional loop in Fortran
body: <p>Hoping someone could help me. I was just introduced to Fortran and can't seem to figure out why my code is producing an infinite loop.</p>
  <p>I want to write a code that finds the root (c) of a function f(x)= x^3 - 3x - 4 between the intervals [2,3]:</p>
  <p>I want the steps to be: initialize a and b.
  Then calculate c = (a+b)/2.
  Then if f(c) &lt; 0, set b=c and repeat the previous step. If f(c) &gt; 0, then set a=c and repeat the previous step.</p>
  <p>The point is to repeat these steps until we get 1e-4 close to the actual root.</p>
  <p>This is what I have written so far and is it producing an infinite loop.</p>
  <p>I am also confused about whether it is a good idea to use the two condition loop (as in the function has to be greater/less than 0 .AND. absolute value of the function has to be less than 1e-4).</p>
  <p>Any help/tips would be greatly appreciated!</p>
  <p>MY CODE:</p>
  <pre><code>PROGRAM proj
  
  IMPLICIT NONE
  
  REAL :: a=2.0, b=3.0, c, f
  INTEGER :: count1
  
  c = (a + b)/2
  
  f = c**3 - 3c - 4
  
  
  DO
     IF (( f .GT. 0.0) .AND. ( ABS(f) .LT. 1e-4)) EXIT
  
     c = (a+c)/2
     f = c**3 - 3c - 4
     count1 = count1 + 1
  
      PRINT*, f, c,count1
  END DO
  
  PRINT*, c, f
  
  END PROGRAM proj
  </code></pre>
  <p>I want to be able to show the iterations and print each step (getting closer to the actual root).</p>