title: Android Java - Runnable confusion
body: <p>I'm learning about Runnable right now and am a little confused with a code I found and how it's running.</p>
  
  <pre><code>j = 0;
  public Runnable test = new Runnable() {
      @Override
      public void run() {
  
          if (j &lt;= 4) { //this is an if statement. shouldn't it run only once?
              Log.i("this is j", "j: " + j);
              handler.postDelayed(this, 2000); //delays for 2 secs before moving on
          }
  
          j++; //increase j. but then why does this loop back to the top?
  
          Log.i("this is j", "incremented j: " + j);
      }
  };
  </code></pre>
  
  <p>When I run this, every 2 seconds j will log from 0 to 4. I don't understand why though, but it does exactly what I need of having a data updated every 2 seconds. </p>
  
  <p>Does run() just keep... running? Which would explain why it keeps looping, kinda. But then if that was the case then even after the if statement finishes j would still be incrementing itself.</p>
  
  <p>Any help in explaining this would help, thanks!</p>