0

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.

  • 1
    this might help you http://stackoverflow.com/questions/1564818/how-to-break-2-loops-in-javascript ? – caramba Mar 26 '14 at 10:42
  • @PratikJoshi: `break` has no effect on jQuery's `each`. Putting it anywhere in the OP's quoted code would be a syntax error. – T.J. Crowder Mar 26 '14 at 10:45

1 Answers1

2

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;
});
Community
  • 1
  • 1
Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281