If/while loop to break or continue
1 view (last 30 days)
Show older comments
Hello. I have setup a simple data set which illustrates the idea of my code. I have trouble setting up the loop to break/continue the current code. The comments explain the purpose of the code. Don't pay much attention to written for loop etc. its just showing its position in the code.
z = [1; 2; 5; 3; 4; 5]
x = [1 2 1 3 4; 3 2 1 2 1; 1 1 2 3 4;1 2 1 3 4; 3 2 1 2 1; 1 1 2 3 4]
limit = 2;
%%We want to compare z to each coloum of x. If value of z exceeds 5, then compared
%%value of x should be excluded. Which mean we only store compared values
%%when z are below 5.
%%We want to do it with a loop which breaks (remove the compared values
%%above of z) and then continues throught rest of the values. We have an
%%idea that a if or while loop could work.
for L:length(z)
if(x > limit)
break/continue
end
4 Comments
Luna
on 27 Mar 2019
%% We want to do it with a loop which breaks (remove the compared values
%%above of z) and then continues throught rest of the values
You say we want to remove here. If it is not removed what is the result for the above arrays and while your limit is 2?
You say "If value of z exceeds 5" you don't want to do a calculation, but you look for if x > limit in the code. I really don't get your question.
Adam Danz
on 27 Mar 2019
Sorry, I still don't have a solid understanding of the goal. The break() function terminates execution of a for-loop. So it can't 'break' and 'continue' at the same time.
Perhaps it would be better to explain the main goal of what you're doing. Also how does the 'limit' variable come into play? Is that the threshold of z that should break the loop?
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!