Can anyone replace FOR loop with WHILE loop?

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2013 年 12 月 9 日
編集済み: Andrei Bobrov 2013 年 12 月 9 日

0 投票

k = 0;
x = 0;
while x >= 0
k = k + 1;
x = 50 - k^2;
end
y = sqrt(x);

2 件のコメント

misha Bilguun
misha Bilguun 2013 年 12 月 9 日
x =
-14 ? why?
x have to plus (+)
Walter Roberson
Walter Roberson 2013 年 12 月 9 日
Not in your code. Your "for" loop tests x<0 after it sets x to the new value. So the loop is not going to end until it is already true that x<0.

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

カテゴリ

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

タグ

質問済み:

2013 年 12 月 9 日

コメント済み:

2013 年 12 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by