How can i plot all the iterations of this while loop?

x=101077571
counter = 0
while x > 1
if mod(x,2) == 0
x=x/2
else mod(x,2) == 1
x= (3*x)+1
end
counter = counter + 1
end

1 件のコメント

KL
KL 2017 年 12 月 5 日
編集済み: KL 2017 年 12 月 5 日
When you write an if-else statement, you do not need to write the condition for "else" case. What you write under else will be executed if your original condition is false. If you have more than one condition you should be using if-elseif-else.

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

回答 (0 件)

カテゴリ

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

質問済み:

2017 年 12 月 5 日

編集済み:

KL
2017 年 12 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by