Why is my while loop infinite?
조회 수: 3 (최근 30일)
이전 댓글 표시
I'm not sure why this loop is running infinitely; shouldn't it end as soon as nVal is equal to the value of inputM?:
clear;
clc;
inpuTm = input('Enter the value for m: ');
nVal = 2;
pofN = [0,1];
while nVal <= inpuTm
pNext = 2*(nVal-1)+(nVal-2);
pofN = [pofN,pNext];
end
disp(pofN);
댓글 수: 0
답변 (1개)
dpb
2018년 11월 3일
Yes, but neither nVal nor inpuTm are modified inside the while loop, so they remain unchanged and the loop either never executes or is an infinite loop depending upon the value of inpuTm.
댓글 수: 4
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!