I tried the callback way and could not get this to work, what you have to understand is that values are still atomic even though execution is not. For example:
alert('1');
<--- these two functions will be executed at the same time
alert('2');
<--- these two functions will be executed at the same time
but doing like this will force us to know the order of execution:
loop=2;
total=0;
for(i=0;i<loop;i++) {
total+=1;
if(total == loop)
alert('2');
else
alert('1');
}