break statement after if loop inside a for loop..

Hi..I have doubt if we are using an if loop inside a for loop followed by a break ,whether the break function will break if loop or for loop ..for example..
for i=1:100
if (statement1)
a=b
break
end
if (statement2)
b=c
in this which loop break will break ..if or for loop..
thanks

 採用された回答

Matt J
Matt J 2014 年 9 月 15 日

0 投票

The break will exit the for-loop. if...end's are not loops.

5 件のコメント

Abhishek sadasivan
Abhishek sadasivan 2014 年 9 月 15 日
I am trying to find how this(below) code is working ..can you able to me help me out.. q=0; k=1; locs_Rwave = [116 410 697]'; locs_Qwave=[110 210 356 457 575 313]'; for j=k:size(locs_Rwave) for i=1:numel(locs_Qwave) if (i== numel(locs_Qwave)) q=[q locs_Qwave(i)]; break; end if( locs_Qwave(i)>locs_Rwave(j)) q=[q locs_Qwave(i-1)]; break; end end end q
Matt J
Matt J 2014 年 9 月 15 日
編集済み: Matt J 2014 年 9 月 15 日
Can't read it. You need to use the
formatting button. Also, now that you understand the behavior of break , what's left to explain?
Abhishek sadasivan
Abhishek sadasivan 2014 年 9 月 15 日
編集済み: Abhishek sadasivan 2014 年 9 月 15 日
the code seems to very confusing ....pls have a look on the code ..
{ locs_Qwave=[ 100 150 90 1175 1 50]';
locs_Rwave=[116 170]';
q=0 k=1
for j=k:size(locs_Rwave)
for i=1:numel(locs_Qwave)
if (i== numel(locs_Qwave))
q=[q locs_Qwave(i)];
break;
end
if( locs_Qwave(i)>locs_Rwave(j))
q=[q locs_Qwave(i-1)];
break;
end
end
end
q }
Matt J
Matt J 2014 年 9 月 15 日
Please use the
button to font the code.
Image Analyst
Image Analyst 2014 年 9 月 15 日
Don't use a { before the code or a q} after the code. Other than that it should work, and the only problem is that you haven't read this: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by