title: Loop gives correct output if script run in steps but not when skript runs from scratch
body: <p>My script contains a while loop:</p>
  
  <pre><code>import numpy as np
  
  
  ptf = 200 #profiltiefe
  dz = 5
  DsD0 = 0.02
  D0 = 0.16 #cm2/sec bei 20°C
  Ds= D0 * DsD0 
  eps= 0.3
  R= 8.314 
  Ptot=101300 
  Te = 20
  dt = 120 
  
  modellzeit = 86400*3 
  J=modellzeit/dt 
  PiA = 0.04 
  CA = PiA*1000/Ptot 
  
  respannual = 10 #t C ha-1 a-1
  
  respmol = respannual/12*10**6/10000/(365*24)
  respvol_SI = respmol * R * (Te+273)/(Ptot*3600) 
  respvol = respvol_SI * 100 
  
  
  I= ptf/dz 
  S = np.zeros(40)
  
  for i in range(40):
      if i &lt;= 4:
          S[i] = respvol/(2*4*dz)
      if i &gt; 4 and i &lt;= 8:
          S[i] = respvol/(4*4*dz)
      if i &gt; 8 and i &lt;= 16:
          S[i] = respvol/(8*4*dz)
  
  
  Calt = np.repeat(CA,len(range(int(I+1))))
  Cakt = Calt.copy()
  
  res_out = range(1,int(J),1)
  
  Cresult = np.array(Cakt)
  faktor = dt*Ds/(dz*dz*eps) 
  
  timestep=0
  #%%
  while timestep &lt;= J:
  
      timestep = timestep+1
  
      for ii in range(int(I)):
  
          if ii == 0:
              s1 = Calt[ii+1]
              s2 = -3 * Calt[ii]
              s3 = 2 * CA
  
          elif ii == int(I-1):
              s1 = 0
              s2 = -1 * Calt[ii]
              s3 = Calt[ii-1]
  
          else:
              s1 = Calt[ii+1]
              s2 = -2 * Calt[ii]
              s3 = Calt[ii-1]
  
  
          result = Calt[ii]+S[ii]*dt/eps+faktor*(s1+s2+s3)
          print(result)
          Cakt[ii] = result
  
      Cresult = np.vstack([Cresult,Cakt])    
  
      Calt = Cakt.copy()
  </code></pre>
  
  <p>What is intersting: If I run the complete script print(result) gives me different (and incorrect) values. But if I add all my constants before and run the loop part of the code (shown above) the loop performs well and delivers the output I want.</p>
  
  <p>Any idea why this might happen?</p>
  
  <p>I am on Python 2.7.5 / Mac OS X 10.9.1/ Spyder 2.</p>