MATLAB: How to Keep Nested For Loop Indexes From Equaling Each Other for loopnested If I have two nested for loops like this, is there a way to skip the iteration where i=j? for i=1:50 for j=1:50 code endend Best Answer Use the continue keyword.for i=1:50 for j=1:50 if j==i continue; % breaks the inner for loop at the current iteration else % Do stuff here fprintf('i=%d, j=%d\n',i,j); end endendIf this response answers your question, please click "accept this answer." Related SolutionsMATLAB: How can i extrapolate the first 15 values of this vector No loops needed lookinto interp1() with "extrapolate" method: x=1:50;v=exp(x/85).*sin(x/9); MATLAB: I want to create a for loop which creates different pairs each time. for i=1:p for j=1:p if (i~=j) disp('i is equal to'); disp(i); disp('j is equal to'); disp(j); end end end Related QuestionHow does ‘break’ workHow we can store value in array using loopHow to save matrices from specific points in a for loopSave data in for loopHow to remove the lines that are not in the cross section of the annulus
Best Answer