Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Issues with while loop

1 回表示 (過去 30 日間)
Marius Reikerås
Marius Reikerås 2020 年 10 月 27 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Im writing a code to check if my input number is bigger than sqrt 132 and is dividable by 11. Under is my code, i get errors and dont understand what im doing wrong. Thanks for any advice!
x = input(' any number ')
odd = rem(x, 2) == 0
while x > sqrt(132)
if x / 11
fprintf( 'correct/n')
else
fprintf('Try again/n')
end
end

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 10 月 27 日
You have no exit criteria for your while loop, which means you are creating an infinite loop.
Do you even need a while loop? It doesn't sound like there are any repeat calculations in your task. Try using an if statement instead.

製品

Community Treasure Hunt

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

Start Hunting!

Translated by