title: print number from 1 to 10 after every 2 seconds
body: <p>i want to print number after every n number of seconds and based on few conditions i am changing the timer as well as i am stopping the print function. i have done like this -- </p>
  
  <pre><code>var myfunc = {
      value   : 1,
      running : false,
      timer   : 1000,
      start   : function(){
          this.running = true;
          clearInterval(this.timeout);
          this.timeout = setTimeout(function() {
              myfunc.execute(myfunc);
          }, myfunc.timer);
  
      },
      execute : function(){
          if(!this.running) return false;
  
          console.log( 'Currently at -- ' + (this.value++) );
  
          if (this.value &gt; 5 ){
              this.changetiming();
          }
  
          if (this.value &gt; 10 ){
              this.stop();
              return;
          }else{
              this.start();
          }
  
      },
      changetiming : function(){
          this.timer = 3000;
      },
      stop : function(){
          this.running = false;
          clearTimeout(this.timeout);
      }
  };
  
  myfunc.start();
  </code></pre>
  
  <p>Now i want to know what is wrong with following code --</p>
  
  <pre><code>for(var i = 0; i &lt;= 10; i++){
      print(i);
  }
  
  
  function print(i){
      setTimeout(function(){
          console.log(i)
      },2000);
  }
  </code></pre>