필터 지우기
필터 지우기

While Loops - TextBook Example

조회 수: 3 (최근 30일)
Maroulator
Maroulator 2014년 8월 9일
답변: Matthew Eicholtz 2014년 8월 9일
I have the following code from my textbook:
ires=2;
while ires<=200
ires=ires^2;
end
I estimate that the above code will run 14 times and give me a final value of 225 for variable ires. When I run the code in MatLab, however, I get 15 runs and a final value of 256 for variable ires. Could anyone provide some insight as to why this may be the case?

채택된 답변

Image Analyst
Image Analyst 2014년 8월 9일

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 9일
You can check how many times your while loop runs
ires=2;
k=0;
while ires<=200
k=k+1
ires=ires^2;
end
In your case k=3 and not 14

Matthew Eicholtz
Matthew Eicholtz 2014년 8월 9일
2^2=4
4^2=16
16^2=256
256>200

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by