Click to See Complete Forum and Search --> : while() loop delay


neil9999
03-16-2004, 12:06 PM
Hi,

On my page I have a while() loop. When it gets to the end, it should wait for a second before begining again. How do I do this?

Something along the lines of:

while(a==b){
doSomething();
wait(1second);
}

Neil

fredmv
03-16-2004, 12:13 PM
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/window.html#1203758

neil9999
03-16-2004, 02:19 PM
Thanks for that, but I don't know how to use it to do what I need. Basically, it should do something like this:

while(a==b){
//do something
//wait 1 second
//go back to start
}

Thanks

Neil

Vladdy
03-16-2004, 02:35 PM
gotta change your logic:

function repeatMe()
{ // do something
if(a!=b)
setTimout('repeatMe()',1000);
}

fredmv
03-16-2004, 02:38 PM
Originally posted by Vladdy
setTimeout('repeatMe()',1000);You could also do (perhaps outside of the function):setInterval(foo, 1000);

neil9999
03-16-2004, 02:44 PM
Thanks both of you, Vladdy's suggestion works just fine, due to what I am doing setInterval() probably won't work (but thanks anyway).

Neil