Javascript foreach loop go to next element on callback
<pre><code>for(var P in ReturnData.Playlist){
    var IsLoaded = false;
    if(PlayerName == "A"){
        LoadNavA(false,false,false, ReturnData.Playlist[P], function(){
            IsLoaded = true;
            alert();
        });
        }else{
        LoadNavB(false,false,false, ReturnData.Playlist[P],function(){
            IsLoaded = true;
        });
    }
    if(IsLoaded == true) continue;
}
</code></pre>

<p>This is for a music playout system. The <code>LoadNavA</code> and <code>LoadNavB</code> functions load a track to the playlist asynchronously. These elements must be in the correct order. When track 3 is loaded earlier than track 2, it first places track 3 and than track 2, but it should start loading track 3 when track 1 and 2 are already loaded.</p>

<p>When the callback in <code>LoadNavA</code> or <code>LoadNavB</code> is called, then the loop should go on. How?</p>
