# Timed Loop

**URL:** <https://forum.kirupa.com/t/timed-loop/282443>\
**Category:** Uncategorized\
**Created:** [February 22, 2009, 4:46am UTC](https://forum.kirupa.com/t/timed-loop/282443 "2009-02-22T04:46:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Keel](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@John\_Keel](https://forum.kirupa.com/u/John_Keel)\
**Post date:** [February 22, 2009, 4:46am UTC](https://forum.kirupa.com/t/timed-loop/282443/1 "2009-02-22T04:46:02Z")

</div>

I am trying to construct a timed loop… so far without success.

What I need is a loop where iteration 0 + i + 1 starts a few seconds after iteration 0 + i. I tried putting a timer inside the loop but the loop seems to simple skip the timer instead of executing it sequentially before starting the next iteration. Here is the code snippet:

```auto

var iTimer : Timer;
                            
for( var i:int = 0; i < 2; i++ )
{
    trace( i + " i iterations" );
                
    iTimer = new Timer( 1000 );
    iTimer.addEventListener( TimerEvent.TIMER, iLoop );
    iTimer.start( );
            
    function jLoop( evt:TimerEvent ):void
    {
        trace( i + " i iterations" );

        iTimer.removeEventListener( TimerEvent.TIMER, jLoop );
        iTimer.reset( );
    }                  
}

```

The loop does not seem to wait for jLoop() to be executed. It speeds ahead onto the next iteration, instantiating a new timer and thus screwing up the timing of the iterations. I have tried different things like putting break and continue statements in there but to no avail. Anyone got an idea?
