フィルターのクリア

Loops: For or While?

4 ビュー (過去 30 日間)
Miriah Dudley
Miriah Dudley 2021 年 4 月 15 日
編集済み: Jan 2021 年 4 月 15 日
What loop would work best to write and complete the bullets below?
  • Initializes a variable number=200;
  • Initializes a variable count=0;
  • Subtracts an integer of your choice from number to get the new number during each step of the loop, until number is less than 10.
  • Updates count to keep track of how many steps are needed.

採用された回答

Jan
Jan 2021 年 4 月 15 日
編集済み: Jan 2021 年 4 月 15 日
If the number of iterations is known in advance, use a FOR loop.
If the number of iterations is not known in advance, but determines by dynamic calculations, use a WHILE loop.
"until number is less than 10" sounds clearly like the number of iterations is determined dynamically.

その他の回答 (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