convert for loop to while

3 次查看(过去 30 天)
sam ham
sam ham 2016-11-9
回答: Adam 2016-11-9
Can someone help me convert this for loop to a while loop?
v=0;
for n=1:length(i);
v=v+i(n);
end

回答(1 个)

Adam
Adam 2016-11-9
v = 0;
n = 1;
while n <= length( i )
v = v + i( n );
n = n + 1;
end
Quite why you would want to do this I don't know but anyway...

类别

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