First, there is never a length cost for using a for loop over a while loop, but you get additional functionality with the for loop, so some coders just always use the for:
for(;<condition>;){}
while(<condition>){}
That said, I think the purpose here may be for consistency with the surrounding code.
For example, here is part of the original code. As you can see, in this code you can stay in the "for" loop mode of thinking the whole time, so it feels more consistent:
if (args) {
if (isObj) {
for (name in object) {
if (callback.apply(object[name], args) === false) {
break;
}
}
} else {
for (; i < length;) {
if (callback.apply(object[i++], args) === false) {
break;
}
}
}
}
Compare this to replacing the second loop with a while. When you read this code, you have to switch from the "for" loop mode of thinking to the "while" loop mode of thinking. Now I don't know about you, but I find it slightly faster for my eyes to switch between the loop conditions above as opposed to the loop conditions below. This is because in the above case I can just concentrate on the conditions, whereas in the below case my eyes are drawn to reread the while and the for each time because they are different:
if (args) {
if (isObj) {
for (name in object) {
if (callback.apply(object[name], args) === false) {
break;
}
}
} else {
while (i < length) {
if (callback.apply(object[i++], args) === false) {
break;
}
}
}
}
while(i<length&&callback.apply(object[i++],args)!==false);