title: Run code every second by using System.currentTimeMillis()
body: <p>I am trying to run a line of code every second by using System.currentTimeMillis();. </p>
  
  <p>The code:</p>
  
  <pre><code>     while(true){
             long var = System.currentTimeMillis() / 1000;
             double var2 = var %2;
  
             if(var2 == 1.0){
  
                 //code to run
  
             }//If():
  
          }//While
  </code></pre>
  
  <p>The code which I want to run, runs multiple times because var2 is set to 1.0 multiple times due to the infinite whole loop. I just want to run the code line when var2 is first set to 1.0, and then every time again when var2 becomes 1.0 after 0.0.</p>