title: Timer inside while loop
body: <p>How would I go about implementing a timer inside a while loop like so in Java?</p>
  
  <pre><code>while (game not ended) {
  //do something
  (wait 5 seconds)
  }
  </code></pre>
  
  <p>Would it be something like so?: (<code>java.util.Timer</code>)</p>
  
  <pre><code>int delay = 1000; //milliseconds
  
      while (game not ended) {
          //do something
          new Timer(delay, taskPerformer).start();
      }
  </code></pre>