Manage to sleep inside a loop - Javascript Statement

Javascript examples for Statement:for

Description

Manage to sleep inside a loop

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  .  ja va 2 s.com
(function() {
    var i = 0,
        action = function() {
            document.write(i + "<br>");
            i++;
            if (i < 10) {
                setTimeout(action, 1000);
            }
        };
    setTimeout(action, 1000);
})();
    }

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

Related Tutorials