My code has the following sturcture. Inside the nested loop I want to break the loop & want to go Statement 1 & Statement 3.
. . .
. . .
. . .
for index = values
Statement 1
Statement 2
Statement 3
Statement 4
if expression
. . .
if expression
[Go to Statement 1]
else expression
[Go to Statement 3]
. . .
. . .
. . .
I have added the lines to clarify further.

 채택된 답변

Walter Roberson
Walter Roberson 2022년 12월 11일

0 개 추천

That is not possible in MATLAB, and will never be possible in MATLAB.
You need a framework something like this
repeat_1 = true;
while repeat_1
repeat_1 = false;
Statement 1
Statement 2
repeat_3 = true;
while repeat_3
repeat_3 = false;
Statement 3
Statement 4
if expression1
if expression2
repeat_1 = true;
break;
else
repeat_3 = true;
continue;
end
end
if ~repeat_3
statements after tests that are to be skipped if you GOTO Statement 3
end
end
if ~repeat_1
statements after tests that are to be skipped if you GOTO Statement 1
end
end

댓글 수: 3

Thanks for your guidance.
I din not understand these portions
"if ~repeat_3
statements after tests that are to be skipped if you GOTO Statement 3
end"
I am going back to my initial structure again to understand your codes-
for index = values
Statement 1
Statement 2
Statement 3
Statement 4
if expression1
. . .
if expression2
[Go to Statement 1]
else expression3
[Go to Statement 3]
. . . Extra C
. . . Extra B
. . . Extra A
Can you please mention which lines are to be skipped if you GOTO Statement 3? Is it the addtional lines that exists in the flow chart below statemet 3 (Extra C)? If not can you mention in the inital flow chart?
repeat_1 = true;
while repeat_1
repeat_1 = false;
Statement 1
Statement 2
repeat_3 = true;
while repeat_3
repeat_3 = false;
Statement 3
Statement 4
if expression1
if expression2
repeat_1 = true;
break;
else
repeat_3 = true;
continue;
end
Extra C
end
if ~repeat_3
Extra B
end
end
if ~repeat_1
Extra A
end
end
However this will warn you that Extra C is unreachable.
Thank you. It helps a lot to solve the flow chart.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

Community Treasure Hunt

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

Start Hunting!

Translated by