Exiting a loop once condition is met

I am trying to write output to a file using if loops such as the one below
if (x(i+1) >= 65.0) && (x(i+1) <= 75.0)
fprintf(fid, '%.2f ', w(i+1), y(i+1), 70, pi*(z(i+1))^2);
fprintf(fid, '\n');
break
end
however, this stops the entire code from iterating until completion. I have tried a similar loop using while but this wrote out multiple records when I just want one written for each loop and then exit the print loop and continue with the main code. How does one accomplish this?

回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 2 月 26 日

0 投票

Perhaps you want continue instead of break

1 件のコメント

Andre
Andre 2014 年 2 月 26 日
Using continue within the if loop has the same result as using the while loop unfortunately and turns while loops into infinite loops using my conditions.

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

カテゴリ

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

質問済み:

2014 年 2 月 26 日

コメント済み:

2014 年 2 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by