Lee wrote:
> Bundy said:
>
>
>>function every_second()
>>{
>> for (x=1; x<5; x++)
>> {
>> setTimeout("second_function()",2000);
>> }
>>}
>
>
> When posting code, please convert TAB characters to spaces.
>
> The setTimeout() function does not insert any delay.
> It simply schedules the expression to be evaluated after the
> specified delay. Once it has been scheduled (which takes
> almost no time at all), processing continues. In your case,
> it then immediately schedules the next invocation of your
> second_function().
>
> The method that Evertjan has posted is generally preferred,
> but as an illustration, here's another way to do what you
> seem to want. Each invocation is scheduled to occur two
> seconds later than the previous one:
>
> function every_second()
> {
> for (x=1; x<5; x++)
> {
> setTimeout("second_function()",2000*x);
> }
> }
>
Thanks
This had me perplexed, now I understand.
Bundy
|