how to step out of a for loop

20 views (last 30 days)
A
A on 10 May 2012
during debugging, I need to complete a for loop and continue debugging line by line; when I press shift+F11 it gets out of debugging mode altogether

Accepted Answer

Sean de Wolski
Sean de Wolski on 10 May 2012
The only thing I can think of to do this is to set an if condition on a variable that you would modify while debugging. E.g:
a = false;
for ii = 1:10;
disp('hello world');
if a;
break
end
end
disp('It''s Thursday!');
So when you want to escape, set a to true from the command line and it will exit the next time the if-condition is hit.
This is unless you wanted the for-loop to complete. If that is the case, just set a breakpoint after the for-loop and click continue.

More Answers (2)

Walter Roberson
Walter Roberson on 10 May 2012
Put your cursor on the first executable line after the loop, and use the mouse menu item to execute until cursor. (Unfortunately there is no known shortcut key for that.)

Honglei Chen
Honglei Chen on 10 May 2012
You can manually set the loop variable to meet the loop ending condition.
  3 Comments
Sean de Wolski
Sean de Wolski on 10 May 2012
This will not work. Any changes made to the for-loop variable are not stored at the end of the loop iteration.
Curiously, break is not working either.
Honglei Chen
Honglei Chen on 10 May 2012
Thanks Walter and Sean, I never realize this.

Sign in to comment.

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!