My for loop is not pausing.

Discussion in 'JavaScript' started by Ali_GGL, Feb 7, 2008.

  1. #1
    Hi have you any idea how to stop a for loop for a few seconds coz i tried it with number of ways and all in vain.
    here is my code.
    
    <script language="javascript">
       for(i=1;i<=3;i++){
         window.setTimeout("alert('Alert for Time " + i  + "')",2000);
       }
    </script>
    
    Code (markup):
    :confused:
     
    Ali_GGL, Feb 7, 2008 IP
  2. nhl4000

    nhl4000 Well-Known Member

    Messages:
    479
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Interesting, I was able to do it like this.
    <script language="javascript">
    var c=0;
    timeout()
    function timeout()  {
    alert(c);
    c=c+1;
    setTimeout("timeout()",2000);
    }
    </script>
    Code (markup):
     
    nhl4000, Feb 7, 2008 IP