Effacer les filtres
Effacer les filtres

How to ignore part of for loops for manual runs?

1 vue (au cours des 30 derniers jours)
Wolfgang McCormack
Wolfgang McCormack le 11 Mar 2021
Réponse apportée : Jan le 11 Mar 2021
Hi everyone,
I have two for loops within each other. Some parts are dependant on the inner loop j. So to finish each loop of i, the entire j should be ran because there are some code out of j that depend on the entire j loop. How can I bypass those lines so that the code foes to the next loop of i when I intend to only run j=1:10
i = 1:100
j = 1:20
modifications
end of j
some modifications based on the entire j (I want to bypass this part so that j = 1:10 runs in its own loop and moves to the next i afterwards automatically)
endof i

Réponse acceptée

Jan
Jan le 11 Mar 2021
for i = 1:100
if condition
nj = 10;
else
nj = 20;
end
for j = 1:nj
...
end
end
Or maybe:
for i = 1:100
for j = 1:20
...
if condition & j == 10
break; % Exit for j loop early
end
end
end

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by