Convert the for loop into while loop without using the break statement

2 ビュー (過去 30 日間)
Kimberley Pereira
Kimberley Pereira 2020 年 3 月 9 日
編集済み: Kimberley Pereira 2020 年 3 月 9 日

採用された回答

Robert U
Robert U 2020 年 3 月 9 日
Hi Kimberley Pereira,
If you want to translate your for-loop into a while-loop, you have to think about, when exactly the loop breaks. That is the case if the if-statement is not fullfilled or i becomes greater 200. Now you can negate the falsification statement and you end up with what is written in the code snippet.
Naming the index variable "i" or "j" is not recommended since the complex number is referenced the same way.
ik = 0;
while value+rounding_error/2 > value && ik<= 200
ik = i+1;
rounding_error = rounding_error /2;
end
Kind regards,
Robert

その他の回答 (0 件)

カテゴリ

Help Center および 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