javascript stopping infinite loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    javascript stopping infinite loop

    Hello,
    Is it possible
    take this example
    Code:
    <script>
    var repeat=true;
    function unlimite()
    {
     while(repeat)
     {
      do some thing;  
     }
    }
    
    function stop()
    {
     repeat=false;
    }
    </script>
    <input type="button" onClick="stop()" value="stop">
    say function unlimite() is running. in this situation user will hit the stop button unlimit function will stop too;

    If it is possible, how to achieve that
    Best Regards,
    Johny
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    doesn’t it work?

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      No it does not, my script is waiting until current function is finished

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You could use setInterval to call the function at set intervals and then clearInterval to clear the timer.

        Comment

        Working...