Recursive function call inside setTimeout() - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window setTimeout

Description

Recursive function call inside setTimeout()

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//w w  w .j av a 2s. c  om
var i = 0;
(function repeat(){
  if (i++ > 5) return;
  setTimeout(function(){
    document.write("Iteration" + i + "<br />");
    repeat();
  }, 5000);
})();
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials