Thread: While loop timer

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    1

    While loop timer

    Hi,

    I am trying to program a 5 second loop timer that resets back to 5 after reaching 0. I have tried but my code gets cannot loop back to 5?
    Code:
    #include <stdio.h>
    #include <unistd.h>
    
    
    int main()
    {
        int start = 5;
    
    
    
    
        while(start > -1)
        {
          if (start != 0)
          {
            printf("%d\n",start);
            start--;
            sleep(1);
          }
          else
          {
            start = 5;
            continue;
          }
    
    
    
    
        }
    
    
        return(0);
    }

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,728
    This code works. Why would you think it doesn't? Do you properly compile it before you run it? You may be running some old version of the executable.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to execute Time Loop in C without clock() and timer ?
    By pixie_laluna in forum C Programming
    Replies: 3
    Last Post: 10-14-2018, 08:26 AM
  2. iterate through loop (timer/bpm)
    By planckepoch in forum C++ Programming
    Replies: 1
    Last Post: 05-23-2018, 08:40 PM
  3. Timer/Loop on Listbox
    By silentkarma in forum Windows Programming
    Replies: 8
    Last Post: 09-13-2006, 09:03 PM
  4. Nested loop timer
    By lineb in forum C Programming
    Replies: 1
    Last Post: 03-05-2006, 04:31 PM
  5. Timer
    By geek@02 in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2005, 11:20 AM

Tags for this Thread