How to Keep Nested For Loop Indexes From Equaling Each Other
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Thomas Schoenstein
am 5 Mai 2020
Kommentiert: Stephen23
am 5 Mai 2020
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
end
end
0 Kommentare
Akzeptierte Antwort
Jason Nicholson
am 5 Mai 2020
Bearbeitet: Jason Nicholson
am 5 Mai 2020
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
end
end
If this response answers your question, please click "accept this answer."
2 Kommentare
Weitere Antworten (2)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!