title: Why is my javascript for loop not working?
body: <p>fourI am writing a javascript for loop and am sure have done a terrible job:</p>
  
  <pre><code>init = function () {
  
      var i = 0;
  
      timer = setInterval(function () {
  
          if (i &gt;= 4) {
              clearInterval(timer);
              return;
          }
  
          for (i = 0; i &lt; 10; i++) {
              console.log('init fired');
          }
  
      }, 2000);
  
  };
  
  init();
  </code></pre>
  
  <p>What I want is for the timer to stop after the <code>i</code> variable in the <code>for</code> loop reaches four. Instead the log is showing <code>init fired</code> ten times. What am I doing wrong?</p>