How many times will this while loop code run

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?

 采纳的回答

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 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by