lo que sigue la for()
puede ser cualquier sentencia; eso puede ser algo con llaves, o puede ser una expresión única, o puede ser una expresión vacía. for (...);
es equivalente a for (...) {}
. Naturalmente, esto solo debe usarse junto con un bucle for que terminará naturalmente, o tendrá un bucle infinito en sus manos.
Las comas son efectivamente punto y coma de segundo grado; hacen declaraciones en su mayoría separadas, pero que funcionarán en un bucle for (y en otro lugar, esta es una definición muy descuidada de ellas).
for (
// initialisation: declare three variables
var j, x, i = o.length;
// The loop check: when it gets to ``!i``, it will exit the loop
i;
// the increment clause, made of several "sub-statements"
j = parseInt(Math.random() * i),
x = o[--i],
o[i] = o[j],
o[j] = x
)
; // The body of the loop is an empty statement
Esto podría ser puesto en una forma más fácil de leer como:
for (
// initialisation: declare three variables
var j, x, i = o.length;
// The loop check: when it gets to ``!i``, it will exit the loop
i;
// note the increment clause is empty
) {
j = parseInt(Math.random() * i);
x = o[--i];
o[i] = o[j];
o[j] = x;
}
Como un bucle while, que podrían ser:
var j, x, i = o.length;
while (i) {
j = parseInt(Math.random() * i);
x = o[--i];
o[i] = o[j];
o[j] = x;
}
Si solo hay un bucle for, el script funcionará, pero si tiene más de uno justo después del otro, debe separar los enunciados. – Rayshawn