Thread: Delay A While Loop

  1. #1
    Registered User
    Join Date
    Sep 2001

    Question Delay A While Loop

    Good day !

    Is there any functions that allows me to slow down a while loop ?

    For example, I wish to display a list of numbers using a While loop and of cauz it's impossible to read all the values in the monitor since the processor speed is quite fast.

    So what should I do in order to have the while loop, loops once and then wait for specific of duration then only continue looping once and wait again and so on ?

    I remember there's a function that allows me do that but i can hardly remember what's that. I try to search around but failed.

    Thanks a lot !

    Sonic Wave

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    Hi. I don't know the library function, but I have one I modified from an example:

    //__Copyright 1997 Chris H. Pappas,Phd. __//

    int poz(int x)
    long T1,T3,T2;
    T3=(time(&T2)) + x;
    while(time(&T2) < T3);

    //Calling syntax:

    poz(2); // ...will pause for 2 seconds

    I am sorry but I don't know the one that pauses for durations shorter than a second, but this should still work in your loops...
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

  3. #3
    You could use either QueryPerformanceCounter

    BOOL QueryPerformanceCounter(
    LARGE_INTEGER *lpPerformanceCount // pointer to counter value

    or timeGetTime

    DWORD timeGetTime(VOID);

    to get precision timing.
    "There's always another way"
    -lightatdawn (

  4. #4
    Registered User
    Join Date
    Aug 2001
    Just use Sleep. Its defined in windows.h and it takes as a parameter the number, in milliseconds, that you want it to delay.


    would delay your program for 1 second.

  5. #5
    Registered User
    Join Date
    Sep 2001

    Smile Thank You !

    Good day !

    Thanks a lot for the advices and recommendations !

    I will look into all of them

    Thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-01-2008, 10:09 AM
  2. Mutiliplcation Program that uses a (do, while, and for loop)?
    By Debbie Bremer in forum C++ Programming
    Replies: 4
    Last Post: 10-11-2008, 06:04 PM
  3. Need advice to provide accurate time delay in C
    By kenkoh in forum C Programming
    Replies: 14
    Last Post: 04-30-2008, 11:13 AM
  4. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM