Author Topic: Delaying A For Statement  (Read 716 times)

How would I delay a for statement from going on for 2500 milliseconds?

Not possible exactly as you stated, you would need to make a recursive algorithm that is slowed by schedules

Not possible exactly as you stated, you would need to make a recursive algorithm that is slowed by schedules
So I'd need to make a function with the for statement only going for a max of 100 and then have the function call itself with a delay of 2500, until I reach the desired number?

So I'd need to make a function with the for statement only going for a max of 100 and then have the function call itself with a delay of 2500, until I reach the desired number?
assuming that's the functionality you want, yes. It seems like you have the idea.

Do you mean...

Code: [Select]
code code code
wait 2.5
for i = 0 to 10
    code code code
code code code

...or...

Code: [Select]
code code code
for i = 0 to 10
    code code code
    wait 2.5
code code code



The first one would be equivalent to...

Code: [Select]
function for1()
{
    codeCodeCode();
    schedule(2500, 0, "for2");
}

function for2()
{
    for(%i=0;%i<10;%i++)
        codeCodeCode();
    codeCodeCode();
}

...whereas the second is equivalent to...

Code: [Select]
function for3()
{
    codeCodeCode();
    for4(0);   //for(%i=0;...
}

function for4(%i)
{
    if(%i<10)   //...%i<10;...
    {
        codeCodeCode();
        schedule(2500, 0, "for4", %i++);   //...%i++)
    }
    else   //Code after the for loop
    {
        codeCodeCode();
    }
}