Hi Friends,
I have a code line having two "Do" loops, one within other. In certain situation arising within inner loop, I want the inner as well as outer "Do" loops to break simultaneously. How to achieve it ? The Break[] function I tried only breaks the inner loop, not the outer one. Here is a simplified example.
R[0] = 0;
dsc = {-6, -5, -4, -3, -2, -1, 0, 1, 2};
X = Reap[X = 1;
Do[Do[If[dsc[[k]] < 0, R[m] = R[m - 1] + 1; Sow[R[m]]; Sow[{m, k}];
X = 1 + k; If[R[m] != R[m - 1], Break[]], Sow[{m, k}];
Break[]], {k, X, 10}], {m, 1, 8}]][[2]]
The o/p of this code is
{{1,{1,1},2,{2,2},3,{3,3},4,{4,4},5,{5,5},6,{6,6},{7,7},{8,7}}}
Here, basically the inner Do loop breaks as soon as the dsc hits a non-negative number and there is no further advancement of R[m] after the m and k hit the values {6, 6} during two Do loops. What I want to achieve is the breaking of m loop as well once dsc[[k]] hits a positive number. So basically I want to see the o/p
{{1, {1, 1}, 2, {2, 2}, 3, {3, 3}, 4, {4, 4}, 5, {5, 5}, 6, {6, 6}}
Will appreciate any suggestion on it.
Thanks