I am slightly confused with what you're asking so I will try answer as best I can by assuming that you're saying what I am thinking.
Taking your algorithm, here is a simple block of code:
alert('i = ' + number + ' in this loop');
This would work via:
alert function is called (alert(0))
loop finishes, i++ (i now =1)
starts again at the end of the loop were i=4 it stops
This is how a standard loop works. Hopefully this is what you need but there is also a possibility that your looking at a run-time error whereby a function is being called on an event call which would need the help of closures but that is a far more complex issue.
Moreover, you might want to have a look at the "While" and "Do-While" loops, but please only do so if you feel that you fully understand the for loop now. http://www.w3schools.com/js/js_loop_while.asp
Please shout if this is not what your looking for (and yes, post some code I can look at to fully understand what you need if you do).