Copy link to clipboard
Copied
Hi Scripters!
Beginning the run with a = 0, I don't know how to quit the level 4 if the "if" condition is OK with a = 0 and come back to the level 1 to play with a = 1!
Thanks for your help!
(^/)
for ( a = 0; a < A; a++ ) {
// ----------------------------------------------------------------------------------------------------------------------------------
for ( b = 0; b < B; b++ ) {
// ----------------------------------------------------------------------------------------------------------------------------------
for ( var c = 0; c < C; c++ ) {
// ----------------------------------------------------------------------------------------------------------------------------------
for ( d = 0; d < D; d++ ) {
// ----------------------------------------------------------------------------------------------------------------------------------
if // OK
continue;
}
}
}
}
Copy link to clipboard
Copied
Hi Obi-wan Kenobi,
deep nested loops are very time expensive. Try to avoid them.
If necessary, put them in functions like this example (back to level before loop a-A)
var a;
function loopInNestedLoops () {
var A = B = C = D = 3;
for ( a = 0; a < A; a++ ) {
// ----------------------------------------------------------------------------------------------------------------------------------
for ( b = 0; b < B; b++ ) {
// ----------------------------------------------------------------------------------------------------------------------------------
for ( var c = 0; c < C; c++ ) {
// ----------------------------------------------------------------------------------------------------------------------------------
for ( d = 0; d < D; d++ ) {
// ----------------------------------------------------------------------------------------------------------------------------------
if (a === 1) {// OK
return a;
}
}
}
}
}
}
loopInNestedLoops ();
Have fun