title: How to make an infinite loop in c++? (Windows)
body: <p>I need for a function to repeat every second. I've tried both</p>
  
  <pre><code>for (;;) {}
  </code></pre>
  
  <p>and</p>
  
  <pre><code>while(true){}
  </code></pre>
  
  <p>But when I run the compiled program, the function runs only once.</p>
  
  <p>Sorry, here is the full function</p>
  
  <pre><code>#define WINDOWS_LEAN_AND_MEAN
  #define _WIN32_WINNT 0x0500 
  #include &lt;windows.h&gt; 
  #include &lt;iostream&gt; 
  
  // do something after 10 minutes of user inactivity
  static const unsigned int idle_milliseconds = 60*10*1000;
  // wait at least an hour between two runs
  static const unsigned int interval = 60*60*1000;
  
  int main() {
  
      LASTINPUTINFO last_input;
      BOOL screensaver_active;
  
      // main loop to check if user has been idle long enough
      for (;;) {
          if ( !GetLastInputInfo(&amp;last_input)
            || !SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0,  
                                     &amp;screensaver_active, 0))
          {
              std::cerr &lt;&lt; "WinAPI failed!" &lt;&lt; std::endl;
              return EXIT_FAILURE;
          }
  
          if (last_input.dwTime &lt; idle_milliseconds &amp;&amp; !screensaver_active) {
              // user hasn't been idle for long enough
              // AND no screensaver is running
              Sleep(1000);
              continue;
          }
  
          // user has been idle at least 10 minutes
          HWND hWnd = GetConsoleWindow(); 
      ShowWindow( hWnd, SW_HIDE ); 
      system("C:\\Windows\\software.exe");
          // done. Wait before doing the next loop.
          Sleep(interval);
      }
  }
  </code></pre>
  
  <p>This run only once instead of continue checking.</p>