Limiting the setInterval function?

 function greet(name) {
            console.log('Hello Good Morning ' + name );
        }

        
        // let timeout = setTimeout(greet, 3000 , "Alapottra");
        // console.log(timeout);

        // clearTimeout(timeout);

       

       let interval =  setInterval(greet , 2000 , 'Jhon');
        
       let count = 0 ; 
       if (count < 4){
           console.log(interval);
           count++
       }else{
           clearInterval;
       }

How to a limit to the interval function like I want it to run 5 times and then stop , I tried using a while loop as well as for loop but it seems like it has no effect whatsoever

49 thoughts on “Limiting the setInterval function?”

Leave a Comment