title: Variables not converging... where's the error?
body: <p>I recently ported this code in from another language. It's supposed to run through some probability estimations and continue running through them until it converges on a solution. Convergence is determined by the maximum change in any probability getting below a certain threshold. This works perfectly in the other language. On the first iteration, the max probability change should be 50%, on the second, it should be 22%, etc. and it should converge fairly fast.</p>
  
  <p>However, in javascript, it's going only two iterations before getting "stuck" and looping infinitely. I'm sure there's a VERY simple error here, but I can't seem to find it for the life of me. Any idea what's going on?</p>
  
  <p>And here's a fiddle: <a href="http://jsfiddle.net/LxLhuc0k/" rel="nofollow">http://jsfiddle.net/LxLhuc0k/</a></p>
  
  <pre><code>var probs = new Array();
  
  for (i=0; i&lt;=99; i++) {
      for (j=0; j&lt;=99; j++) {
          for (k=0; k&lt;=99; k++){
              probs[i,j,k]=.5;
          }
      }
  }
  
  var maxChange=100;
  
  while (maxChange&gt;.01) {
      maxChange=0;
  
      for (i=0; i&lt;=99; i++) {
          for (j=0; j&lt;=99; j++) {
              for (k=0; k&lt;=99; k++){
                  oldValue=probs[i,j,k];
  
                  probs[i,j,k]=Math.max(
                      .2125*getValue(i,j,k+1)
                      +.3900*getValue(i,j,k+5)
                      +.0920*getValue(i,j,k+10)
                      +.0370*getValue(i,j,k+15)
                      +.0560*getValue(i,j,k+20)
                      +.0008*getValue(i,j,k+25)
                      +.0016*getValue(i,j,k+40)
                      +.0001*getValue(i,j,k+60)
                      +.2100*(1-getValue(j,i,0))
  
                      ,1-getValue(j,i+k,0)
                  );
  
                  if (Math.abs(probs[i,j,k]-oldValue)&gt;maxChange) maxChange=Math.abs(probs[i,j,k]-oldValue);
              }
          }
      }
  
      alert(maxChange);
  }
  
  alert('Done!');
  
  function getValue(x, y, z) {
      if (x+z&gt;99)    return(1);
      if (y&gt;99) return(0);
      return(probs[x,y,z]);
  }
  </code></pre>