Javascript: Break from loop
<p>I want to keep checking a list until it finds an item that is available. For each item in the list it will make a post request to check if the item is available. I want to keep it asynchronous. Also note that i am using ajaxq function not ajax function, that is because i am using this queuing script <a href="http://code.google.com/p/jquery-ajaxq/" rel="nofollow">http://code.google.com/p/jquery-ajaxq/</a>. So it won't be over before it's started sorta-thing. I'm sure thats not the problem though.</p>

<p>I need a way to break out of the loop once a item is available, so i can't just use a callback function because it won't be able to break out of the loop inside a function. 
So i thought incrementing a variable if its done and using a do-while loop would work, but it just freezes my browser like it's a never-ending loop.</p>

<p>Any suggestions on how do fix this or do it a better way would be great.</p>

<pre><code>do {

    var d = 0;
    for(var i in list) {

        var item = list[i];

        $.ajaxq('queue', {
            type: 'POST',
            url: baseURL + '/ChangeItem/Check',
            data: {
                'newItem': item, 
                'purchaseItem': false
            },
            error: function(jqXHR, textStatus) {
                alert(textStatus);
            },
            dataType: 'text',
            success: function(data) {
                if(thisObject.isNotTaken(data)) {
                    d++;
                    thisObject.claimItem();
                }
            }
        });
    }

} while(d == 0);
</code></pre>
