title: How to make a setInterval stop after some time or after a number of actions?
body: <p>I've created a loop of &quot;changing words&quot; with jQuery
  by using the code in this answer:
  <a href="https://stackoverflow.com/questions/7425231/jquery-find-word-and-change-every-few-seconds">jQuery: Find word and change every few seconds</a></p>
  <p>How do I stop it after some time? Say after either 60 seconds or after it has gone through the loop?</p>
  <pre><code>(function() {
  
    // List your words here:
    var words = [
        'Lärare',
        'Rektor',
        'Studievägledare',
        'Lärare',
        'Skolsyster',
        'Lärare',
        'Skolpsykolog',
        'Administratör'
      ],
      i = 0;
  
    setInterval(function() {
      $('#dennaText').fadeOut(function() {
        $(this).html(words[i = (i + 1) % words.length]).fadeIn();
      });
      // 2 seconds
    }, 2000);
  
  })();
  </code></pre>