Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Issues with while loop
조회 수: 9 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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.
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!