How to ignore part of for loops for manual runs?

1 view (last 30 days)
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

Accepted Answer

Jan
Jan on 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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!