title: Delay execution 1 second
body: <p>So I am trying to program a simple tick-based game. I write in C++ on a linux machine. The code below illustrates what I'm trying to accomplish.</p>
  
  <pre><code>for (unsigned int i = 0; i &lt; 40; ++i)
  {
      functioncall();
      sleep(1000); // wait 1 second for the next function call
  }
  </code></pre>
  
  <p>Well, this doesn't work. It seems that it sleeps for 40 seconds, then prints out whatever the result is from the function call.</p>
  
  <p>I also tried creating a new function called delay, and it looked like this:</p>
  
  <pre><code>void delay(int seconds)
  {
      time_t start, current;
  
      time(&amp;start);
  
      do
      {
          time(&amp;current);
      }
      while ((current - start) &lt; seconds);
  }
  </code></pre>
  
  <p>Same result here. Anybody?</p>