title: Best way in javascript to repeatedly repeat a function?
body: <p>I'm doing some visualisation of a 'network evolution model' like thing.<br>
  The basic algorithm is:  </p>
  
  <ul>
  <li>some init operations  </li>
  <li>100 evolution steps  </li>
  <li>some operations  </li>
  <li>100 evolution steps  </li>
  <li>some other operations  </li>
  <li>100 evolution steps  </li>
  <li>begin from first step (i.e. the init ops)  </li>
  </ul>
  
  <p>So basically, I have to repeat the 100 evolution steps 3 times with unique operations to be done in between, before it all starts again from the beginning.</p>
  
  <p>My current code is somewhat structured like this:  </p>
  
  <pre><code>var timer;
  var counter;
  function bigFunction() {
  
      function hundredSteps() {
  
          // code for single step
  
          timer = setTimeout(hundredSteps(), 10);
          counter++;
          stage++;
  
          if (counter &gt;= 100) {
              clearTimeout(timer);
              counter = 0;
              nextStage(stage);
          }
      }
  
      function nextStage(stage) {
  
          if (stage == 1) {
              // 1st step code, some init operations
              timer = setTimeout(hundredSteps(), 10);
          }
  
          if (stage == 2) {
              // 2nd step code, some operations
              timer = setTimeout(hundredSteps(), 10);
          }
  
          if (stage == 3) {
              // 3rd step code, some other operations
              stage = 0;
              timer = setTimeout(hundredSteps(), 10);
          }
      }
  
      var stage = 1;
      counter = 0;
      nextStage(stage);
  }  
  </code></pre>
  
  <p>So I wanted to ask: Is this a 'proper' way to code what I want to achieve? Or would one usually do it differently? </p>