While loop doesn't terminate
조회 수: 1 (최근 30일)
이전 댓글 표시
In an attempt to have Matlab compute the sum S = 0.1 + 0.2 + . . . + 0.9, someone writes the following code:
s = 0
x = 0
while x~=1.0
s = s + x
x = x + 0.1
end
S = s
(a) Test this code on Matlab. Why does the program keep running indefinitely? Note: to terminate the procedure, place the cursor in the command window and press Ctrl + C.
(b) What should be changed in the code to make it stop?
댓글 수: 1
Rik
2019년 10월 15일
For this specific question, I suggest using the debugger to step through your code line by line.
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!