Timing Code

Status
Not open for further replies.

NCISAGENT

Baseband Member
Messages
43
What code do you use to create a delay in the processing of the code

in other words....say you want to make a small amount of time to wait inside of a for loop each time it executes?
 
This all depends on what language you're using. I do it highly inefficiently: I store the current system time in a variable. Then I add the time to it that I want it to loop for (say, 5 seconds). Then I do a while loop (while the system time is less than the variable that holds the altered time). Inside the loop, there's no code, but it'll still loop for 5 seconds.

I know there are much more efficient ways to do it (there are Timer APIs, I think), but that way has worked for me.
 
Im using C++ (Borland 6.0)

I want to have absolutly no processes from the program while the computer waits---I dont know if that is possible but what you have suggested seems to process empty code...right?

Also - Im not a C++ wizard .... but how do you grab the system time?
 
I am using Borland 5.0 so this should work for you. windows.h has a function called Sleep(); which allows you to set a time, in milliseconds, to pause. For example, if you wanted your program to pause for 500 milisecs (half a second) you would type Sleep(500);
*note the 'S' in Sleep must be capitalized.
 
Status
Not open for further replies.
Back
Top Bottom