How do I do something every x increment in time?
From: wwwolf (abuse_at_alltel.net)
Date: 03/30/05
- Next message: Barry Schwarz: "Re: why does this happen?"
- Previous message: Anthony Borla: "[OT - gdb-specific] Re: Print variable with gdb??"
- Next in thread: Barry Schwarz: "Re: How do I do something every x increment in time?"
- Reply: Barry Schwarz: "Re: How do I do something every x increment in time?"
- Reply: CaptainJ: "Re: How do I do something every x increment in time?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Mar 2005 19:38:31 -0500
How do I write code that executes a statement every 0.25 seconds while other
conditions are still being evaluated? (I hope I got the terminology right)
Psuedocode:
1. Set up a timer to display a message 5 seconds from now.
2. While 1 is activated, "cout << "." << flush;" once every 0.25 seconds until 1
is ready to print its message.
I understand I will need 2 time variables. 1 will be "timer" and 2 will be
"dotDelay". I think I will need to evaluate dotDelay and any dotDelay
statements while it is placed inside the "timer while block" since this block
needs to keep control. Or, dotDelay needs to be given control to execute its
statement every 0.25 seconds and then pass control back to the timer loop.
I've noticed that loops will 'delay' the next statement outside of their block
loop until the loop returns false. At first I tried to set up a while loop
inside of another while loop to 'delay' the "." message. It did exactly what I
told it to (not what I wanted) by delaying the "." until x time and then
continue to blast the screen with the "." message until timer was ready to
cout.
1. What is the terminology called for the block that executes a statement every
x increment in time?
2. Is this where a function would be needed?
Could someone show me an example of how to set this up?
Thanx again for your patience.
// Example for 5 second timer w/ delay dot
#include <iostream>
#include <ctime>
int main()
{
using std::cin;
using std::cout;
using std::flush;
time_t timer = ((time (0)) +5); // Add 5 sec to current time
while( timer >= time (0) ) // Compare the timer w/ current time
{
cout << "." << flush; // Would like this to only execute every 0.25
seconds
}
cout << "\nFive seconds have passed.\n" << flush;
return 0;
}
If I have gotten any terminology wrong then plaease correct me. One of the best
tools for learning is being able to ask the right questions.
Thanx again,
- Next message: Barry Schwarz: "Re: why does this happen?"
- Previous message: Anthony Borla: "[OT - gdb-specific] Re: Print variable with gdb??"
- Next in thread: Barry Schwarz: "Re: How do I do something every x increment in time?"
- Reply: Barry Schwarz: "Re: How do I do something every x increment in time?"
- Reply: CaptainJ: "Re: How do I do something every x increment in time?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|