title: Loops and iterations
body: <p>Is there a way that a function has 2 options of return and the option of return is chosen after a certain interval of iterations?</p>
  <p>example:
  a function that swaps from &quot;a&quot; to &quot;b&quot; and &quot;b&quot; to &quot;a&quot; after 4 iterations returns:</p>
  <p>a
  a
  a
  a
  b
  b
  b
  b
  a
  a
  a
  a
  b
  b
  b
  b
  .
  .
  .</p>
  <p>Edit I did something like this to solve the problem:</p>
  <pre class="lang-js prettyprint-override"><code>var counter = 0;
  var state = true;
  
  var changeState = function(){
      var x = 0
      while(x != 12){
          if(counter == 4){
              counter = 0;
              state = !state;
          }
          if (state){
             console.log(&quot;a&quot;);
          } else {
              console.log(&quot;b&quot;)
          }
          counter += 1;
          x += 1
      }
  }
  
  changeState();
  </code></pre>