• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to come back to the loop 1! …

LEGEND ,
Mar 26, 2017 Mar 26, 2017

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;

            }

        }

    }

}

TOPICS
Scripting

Views

198

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 26, 2017 Mar 26, 2017

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines