How to stop setTimeout? in a for loop

there is a requirement
to output a paragraph of text to a div every 10 seconds. After 50 cycles, the loop starts from 0 until the close button is clicked to stop the loop.

the following is the code I wrote earlier, but cleartimeout doesn"t work because the for loop activates settimeout again. Is there a good way to do it?

for (let i = 0, len = this.params.playTimes + 1; i < len; iPP) {
    this.playText = setTimeout(() => {
        this.fillText(i);
        var myDate = new Date();
        console.log(i,myDate.toLocaleString());
    }, i * this.params.speed * 1000);
}
// setTimeoutfor todo
clearTimeout(this.playText);
Apr.07,2021

if you want to trigger every 10 seconds and terminate after 50 times, why not use setInterval?

var count = 1;
var fixTextInterval = setInterval(function() {
        dosomething();
        countPP;
        if(count > 50) count = 1;
   }, speed*1000);

btnStop.click(function() {
    clearInterval(fixTextInterval);
});
Menu