For reasons entirely beyond my comprehension, this function runs just fine:
function foo() {
var loop = true;
var abc = ["a","b","c"];
var ctr = 0;
while(loop) {
$("<img />").error(function () {
loop = false;
}).attr('src','images/letters/'+abc[1]+(ctr++)+".jpg");
alert(ctr);
}
}
But moving the alert(ctr) outside the while triggers an infinite loop.
function foo2() {
var loop = true;
var abc = ["a","b","c"];
var ctr = 0;
while(loop) {
$("<img />").error(function () {
loop = false;
}).attr('src','images/letters/'+abc[1]+(ctr++)+".jpg");
}
alert(ctr);
}
Can anyone help clarify?