|
-
Jan 10th, 2001, 01:09 PM
#1
Thread Starter
Frenzied Member
Hi all!
I want to make a loop that decrease a variable by one each time it loops. This I have covered so far, but I also want the loop to wait 1 or 2 secs. before it loops again.... Is this possible???
-
Jan 10th, 2001, 01:13 PM
#2
Monday Morning Lunatic
How accurate does it need to be?
Code:
for(int i = 5; i > 0; i--) {
// Do something
Sleep(1000); // Pause for 1 second
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 10th, 2001, 01:39 PM
#3
Frenzied Member
You can use GetTickCount() to return a long integer containing the number of milliseconds the system has been running. If you check the difference between the current time and a start time you can wait until a second has passed, independant of how long the code in your loop takes to execute (assuming it doesn't take more than 1 second). You can do it like this:
Code:
long LastTime = GetTickCount();
for(int i=5; i>0; i--)
{ // Do something
while(GetTickCount() < LastTime + 1000); // Pause for 1 second
LastTime = GetTickCount();
}
Harry.
"From one thing, know ten thousand things."
-
Jan 10th, 2001, 01:41 PM
#4
Monday Morning Lunatic
You can get 1ms resolution by using the multimedia timers.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 10th, 2001, 02:56 PM
#5
Thread Starter
Frenzied Member
I think you suggestion will do parksie! Thanks to you and Harry!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|