how to step out of a for loop
조회 수: 20 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Sean de Wolski
2012년 5월 10일
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.
댓글 수: 0
추가 답변 (2개)
Walter Roberson
2012년 5월 10일
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.)
댓글 수: 0
Honglei Chen
2012년 5월 10일
You can manually set the loop variable to meet the loop ending condition.
댓글 수: 3
Sean de Wolski
2012년 5월 10일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!