title: Exit a loop at anytime
body: <p>I'm trying to exit a loop at anytime I want by pressing any key. I've tried the code below but it can't be done. Gotta need your help. Thank you in advance. I'm using a C-Free 5.0.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  int main(void)
  {
      int b=0, i;
      int seconds;
      printf("\nEnter number of seconds : ");
      scanf("%d", &amp;seconds);
      while (b==0)
      {
          for(i=1;i&lt;=seconds;i++)
          {
              time_t end = time(0) + 1;
              while(time(0) &lt; end)
              ;
              seconds -= 1;
              printf("Number of seconds left : %d\n", seconds);
              b=kbhit();
          }
  
          if(seconds == 0)
          {
              exit(0);
          }
      }
      printf("Number of remaining seconds left : %d\n", seconds);
  }
  </code></pre>