What is the code that terminates the program and stop it?

 採用された回答

Image Analyst
Image Analyst 2016 年 12 月 25 日

0 投票

Try this:
again = true; % Flag for iterating the outer while loop again.
loopCounter1 = 1; % Count iterations to prevent infinite loop. This is a "fail safe".
loopCounter2 = 1; % Count iterations to prevent infinite loop. This is a "fail safe".
maxIterations = 9999; % Whatever is the most you ever expect.
while condition1 && again && loopCounter1 < maxIterations
while condition2 && loopCounter2 < maxIterations
if condition3
% statements
% increment counter
break; % Breaks out of inner while loop only, loop #2.
else
% Here i want to break out without return to any while
again = false; % Make sure outer while loop does not iterate again.
break;
end
% Increment counter
loopCounter2 = loopCounter2 + 1;
end
% Increment counter
loopCounter1 = loopCounter1 + 1;
end

1 件のコメント

mikel ku
mikel ku 2016 年 12 月 25 日
Thaaank you

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 12 月 25 日

0 投票

need_to_finish = false;
while ( )
while ( )
if ( )
% statements
%increment counter
break
else
% here i want to break out without return to any while
above(finish program)
need_to_finish = true;
end
if need_to_finish
break;
end
end
if need_to_finish
break;
end
%%increment counter
end

1 件のコメント

mikel ku
mikel ku 2016 年 12 月 25 日
Thaaaak you

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

質問済み:

2016 年 12 月 24 日

コメント済み:

2016 年 12 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by