"for (;;)" syntax in JavaScript?

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:
  • 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;
        }
    }
};
It's just personal preference. You could also just use a while(true) {}. The for variant is less characters to type.
Danke schön!
I'm still learning, but as far as I could tell, there is a difference between 'do {} while {}' and 'while() {}' --> the first way is guaranteed to execute at least once where the second way might not execute at all. Though, I suppose one could simply write the condition in a way that guarantees execution.
But between 'for' and 'while', I understand now it's just a personal preference. If there is any true performance difference I'm sure that it won't show in RMMV (maybe in advanced math or something).

Off-topic:
Ich habe dein "Jump into Javascript" gelesen, es ist sehr hilfreich. Weißt du, ob jemand ein "Flow Diagram" für "RMMV Class/Inheritance" erstellt hat? Ich dachte daran, einen zu machen.

(Please excuse any poor grammar, I am a beginner to both German and JavaScript)

EDIT: Just realized it's not your "Jump into Javascript", I saw it in your signature. Question still stands though 😀
The main difference between "while" and "for" is application.
"while", while powerful, can also be quite costly. An improperly written "while" loop can crash your application.
A "for" loop is great when you want to iterate a certain amount of times. For example you want to generate X tiles, where X is variable. Yes, as Wayne has mentioned, you can use a while(true), but you will need to be responsible about exiting it.
"While" could be great for calculating, say, projectiles on screen and deleting them:
while (!empty(projectile_list)) {
var projectile = array_shift(projectile_list);
delete(projectile);
}
(this is pseudocode to make an example, it won't actually work =))

In terms of "when to use one and not the other", use a simple rule for when to use "while" loops - "while a condition holds true".
Example: While hp not zero, while on map 2, while character2 is in party etc.
For-loop is an iteration through items. For loop is great for checking/parting an array or an object.

And on top of that, there is also bench-marking of different scripts.
This is for regular browsers and web JS: https://jsperf.com/fastest-array-loops-in-javascript/2
In general, using for-in loops is recommended for large number of iterations.
Greetings Aloe Guvner,

Proper for loops make your code a lot clearer, more concise & easier to read by another person than a while loop.

Example:
Code:
var script_list = document.getElementsByTagName('script')

for (var i = 0; i < script_list.length; i ++) {
    var script = script_list[i]

    console.log(script.src)
}
You can do rewrite the code with 'while', but it is not as clear.​

Sincerely,

Joy Diamond.

P.S.: Since the example given is an array, you could use the .foreach method; however, the example was given for clarity, imagine a similar thing on a non-array.

P.P.S.: The for syntax comes from the C language (read the previous link for a good explanation of the full syntax) -- Also it has a good Live demo of a 'for' loop in C.

Spoiler: Nice pretty picture from above link explaining for loops work best when using the 'init', 'condition', and 'increment' code for clarity & conciseness
upload_2017-12-3_7-0-43.png
I was poking around the engine yesterday and found another instance of the "for" loop that is a bit of a while-for hybrid - foreach.
A fore-each loop will iterate through a list of object automatically, while there are elements to handle.
Per my benchmark above it is, actually, the most efficient method.
Here is an example using one of the GameObject classes from MV:

Code:
$gameParty.members().forEach( function( actor ) {
    if  ( actor.actor().ams_bs_bust ) {
        my_function_something( actor.actor().ams_bs_bust );
    }
}, this );
I kind of forgot to mention that in my last post.
And to my knowledge strong-types languages like C do not have ForEach, but its been a while since the last time I've used C.

Original thread: https://forums.rpgmakerweb.com/threads/for-syntax-in-javascript.87924/