while and for loop
5 views (last 30 days)
Show older comments
Muhammad Ridwanur Rahim
on 23 May 2018
Edited: Ameer Hamza
on 23 May 2018
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?
Accepted Answer
Ameer Hamza
on 23 May 2018
Edited: Ameer Hamza
on 23 May 2018
add inside for loop
if x==3 % or if x < 4
break
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!