while and for loop
3 次查看(过去 30 天)
显示 更早的评论
hi,
i have a very complex code. but the simplified version is this-
x=10
while x>3
for i=1:10
%some task which reduces the value of x, lets say
x=x-1
end
end
so basically what i want is that i want to get out of the while loop when x becomes less than 4. but matlab runs the for loop 10 times. i want matlab to run the for loop for 7 times. how do i do this?
采纳的回答
Ameer Hamza
2018-5-23
编辑:Ameer Hamza
2018-5-23
add inside for loop
if x==3 % or if x < 4
break
end
0 个评论
更多回答(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!