Hi there,

I'm trying to figure out how I would get a for loop to run after a timer has elapsed. So when the timer elapses it circles through the for loop once, then the timer starts again and then goes through when it finish again until the required value has been achieved.

I'm using this with a speed variable so that the speed decreases incrementally rather than instantly as at the moment the for loops seems to go from 10-1 too fast.

public void time(object source, ElapsedEventArgs e)
{
timeB = true;
SlowTimer.Interval = 500;
SlowTimer.Enabled = true;
}

public void decceleration(object source, ElapsedEventArgs e)
{
SlowTimer.Interval = 500; // SlowTimer is the defined out of the scope.
SlowTimer.Enabled = true;
SlowTimer.AutoReset = false;
SlowTimer.Elapsed += new ElapsedEventHandler(time);
int[] slowSpeed = new int[10] {10,9,8,7,6,5,4,3,2,1 }; // new array 1-10

if(timeB == true && SlowTimer.Enabled == true)
{

for (int i = 0; i < 10; i++) // for loop
{
int speed = 0;
speed = slowSpeed[i];
mSpeed = speed; // sets mSpeed to the value of i in the dashSpeed array

timeB = false;

if (mSpeed == 1)
{
horizontalSwimBehaviour(); // changes it back to the normal swimming
rand = 1;
}
}
}
}

Thanks.