<script type="text/javascript"> function test(){ var i =0; // (function(){ if(i>=5){alert('doen!');return;} alert(i); i++; window.setTimeout(arguments.callee,2000); //})(); } //test(); </script>