title: How to stop a function from running on encountering a condition on python?
body: <p>I'm trying to solve/simulate a material balance equation in Python. I want to stop the simulation when one of the concentration values goes negative. I've used a conditional statement followed by break function. There is no error displayed. I'm not understanding as to why that is not working. Is the placement of break statement right? Please help!!
  Here is my code:</p>
  
  <pre><code>def simulation(z,t,k):
  
      k1 = k[0]
      k2 = k[1]
      k3 = k[2]
      tol = z[0] 
      H = z[1]
      O = z[2] 
  
  
      dHdt = k1*tol*H - k2*tol*H
      dtoldt = (-k1 * tol * H) - (k1 * tol * H) - (k3 * tol * O)
      dOdt = -k3*tol*O
  
      for i in range (0,3):
          if z[i] &lt; 0:
             break
  
     return [dHdt, dtoldt, dOdt]
  
  k = [125.656, 478.36, 2698.3]
  t = np.linspace(0, 1000, 100)
  z0 = [100, 150, 200]
  
  z = odeint(simulation, z0, t, args=(k,))
  print(z)
  </code></pre>