While loop: value increases, break if not.
2 次查看(过去 30 天)
显示 更早的评论
Is it possible to use while loop that checks if the variable is increasing each step and break if not?
Or I have to use for loop, something like this:
for i=2:N
if x(i-1)>x(i)
x(i)=0;
end
end
0 个评论
采纳的回答
OCDER
2017-11-20
You could use a while loop instead to run until a conditions is met, and it'll automatically break.
i = 2;
while x(i) <= x(i-1)
i = i+1;
end
Or, you could use a break statement.
for i = 2:N
if x(i) > x(i-1)
break
end
end
更多回答(0 个)
另请参阅
类别
在 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!