01-29-2014 12:23 PM
how can I configure a timed loop to execute upon entry, rather than waiting for the first delta time?
If my delta time is 10 seconds, I get my first execution after 10 seconds. I would like to execute the loop when it is initially entered (second 0) then wait every 10 seconds after that.
Thanks.
Solved! Go to Solution.
01-29-2014 12:52 PM
I don't think you want to use a Timed Loop here.
Timed Loops are meant mainly for RealTime systems which need to be deterministic on relatively short timescales.
For a 10 second wait, you should be using a normal loop with a 10 second wait inside of the the loop.
01-29-2014 12:53 PM
What are you seeing that makes you think things are executed after the loop is done instead of immediatley? Can you let us see your problem code?
01-29-2014 01:37 PM
Thanks, but you're missing the point. The 10 second timing is to demonstrate the problem I'm trying to solve.
01-29-2014 01:40 PM
Here is a very simple example. You will notice that the initial increment of the iteration counter occurs after a 5 second wait, which is the delta time. I would like this to execute immediately then every 5 seconds thereafter. (Sorry for changing the 10 seconds to 5, but wanted a shorter time)
01-29-2014 01:47 PM
The first iteration of a loop, any loop, is iteration 0. That will not change to iteration 1 until the next iteration has started. This is expected behavior. Anything inside the loop will execute immediately but the iteration counter won't increment until the next iteration starts.
01-29-2014 01:56 PM
Set your iteration count to -1 before running. Then you will see that the iteration goes to 0 for the first iteration (yes, i is 0 based) quite quickly.
01-29-2014 02:05 PM
copy the code inside the timed loop and put the copy outside of the loop. This way, the code will execute once before entering the timed loop.
01-29-2014 02:09 PM
@jyang72211 wrote:
copy the code inside the timed loop and put the copy outside of the loop. This way, the code will execute once before entering the timed loop.
Having redundant code accomplishes nothing. The code will already execute immediately on each iteration of the loop.