I was reading through some of the engine JS code to try to learn it more and came across the method/function below.
At first, I was so confused. What is "for ( ; ; )" ?
I ran some tests and found out that it is simply an infinite loop which is broken by the 'break' keyword.
My question for any experienced JavaScripters:
At first, I was so confused. What is "for ( ; ; )" ?
I ran some tests and found out that it is simply an infinite loop which is broken by the 'break' keyword.
My question for any experienced JavaScripters:
- Why not use a "Do { } While { }" loop instead?
- Is the "for ( ; ; )" more efficient in general?
- Is there a certain coding convention that decides which one to use?
Code:
Game_Actor.prototype.releaseUnequippableItems = function(forcing) {
for (;;) {
var slots = this.equipSlots();
var equips = this.equips();
var changed = false;
for (var i = 0; i < equips.length; i++) {
var item = equips[i];
if (item && (!this.canEquip(item) || item.etypeId !== slots[i])) {
if (!forcing) {
this.tradeItemWithParty(null, item);
}
this._equips[i].setObject(null);
changed = true;
}
}
if (!changed) {
break;
}
}
};