How many times does the following code run?
total = 0;
while (total < 100)
total = total + 5;
disp(total)
end;
I thought it was 20, but I am wrong?

 채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 9일

0 개 추천

It depends on whether you are counting the number of times the "while" statement executes or the number of times it will print a number. It will print 20 numbers, 5:5:100 . But the total<100 will execute one extra time to determine that the loop has ended.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2017년 3월 9일

댓글:

Jan
2017년 3월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by