title: JavaFX pausing during for loop WITHOUT using Thread.Sleep()
body: <p>I'm coding this in JavaFX using a FXMLController and the scene builder.
  I'm currently creating an Instagram "liker" mostly just for practice as I'm a Computer Science major, and I just like coding.</p>
  
  <p>My issue is, I have a for loop that "likes" 20 photos for each hashtag, I obviously need a delay or I'd get banned rather quickly. The user can choose the delay, then I randomize this delay so it's not too robotic.</p>
  
  <p>The only way I've been able to use this delay is through the thread.sleep method, but since I'm coding on the FXMLController, it freezes the whole UI, and somehow stops other textareas from being updated. This is obviously not ideal.</p>
  
  <p>I've looked everywhere trying to find an alternative to this, but I can't find anything that works in my program.</p>
  
  <p>I'll give the whole method:</p>
  
  <pre><code>    private void start() {
      sleepWhen();
      tagNumber++;
      int delays = Integer.valueOf(delay.getText());
      delays = delays * 1000;
      if (loaded) {
          runTime.clear();
          runTime.appendText("Liking...");
          for (int i = 0; i &lt; 20; i++) {
              webEngine.executeScript("document.getElementsByClassName('btn btn-default btn-xs likeButton')[" + i + "].click()");
              try {
                  double random = Math.random() * 1000;
                  random = random + delays;
                  delays = (int) random;
                  System.out.println(delays);
                  likes++;
                  likesNumber.clear();
                  likesNumber.appendText(String.valueOf(likes));
                  System.out.println(String.valueOf(likes));
                  Thread.sleep(delays);
                  delays = Integer.valueOf(delay.getText());
                  delays = delays * 1000;
  
              } catch (InterruptedException ex) {
                  //do nothing
              }
  
              System.out.println("tag number" + tagNumber + "numbertags" + numberTags);
              if (!sleep) {
                  if (tagNumber &lt; numberTags) {
                      System.out.println("Loading tag:" + tagNumber);
                      loadTag(tagNumber);
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>This likes 20 photos, then loads another hashtag, and repeats.</p>
  
  <p>Any help with this would be great, thanks.</p>