user3463702
user3463702

Reputation: 23

How to exit to main loop in javascript

these loops are iterating through arrays.

arrayFinalValues = [];
    $(arrayAccessRightID).each(function (i, val) {
        $(arrayNodeID).each(function (j, val1) {
            arrayFinalValues.push(val);
            arrayFinalValues.push(val1);
            $(arraySelectedValues).each(function (k, val2) {
                arrayFinalValues.push(val2);
                if (arrayFinalValues.length % 6 == 0)
                    return false;
            });
        });
    });

in the inner most loop when six elements are entered i want again to start from the outermost loop and in the inner most loop the index should start from next 4th element i.e., i want to in the structure 1,1,T,T,F,F,1,2,F,F,F,F. and so on. that is in the inner most loop the index should start from next elements.when i use return false in inner most loop it again starts with 0.i tried labels but its now working.

Upvotes: 0

Views: 258

Answers (1)

Yasser Shaikh
Yasser Shaikh

Reputation: 47784

Try this, taken from here

$(arrayAccessRightID).each(function (i, val) {
    var shouldExit = true;
    $(arrayNodeID).each(function (j, val1) {
        arrayFinalValues.push(val);
        arrayFinalValues.push(val1);
        $(arraySelectedValues).each(function (k, val2) {
            arrayFinalValues.push(val2);
            if (arrayFinalValues.length % 6 == 0)
            {
              shouldExit = false;
              return shouldExit;
            }
        });
        return shouldExit;
    });
    return shouldExit;
});

Upvotes: 2

Related Questions