HOW TO EXIST FROM A LOOP AND COME BACK TO IT AND THE ITERATION NUMBER CHANGE

2 views (last 30 days)
hello,
i'm working on algorthim that has two for loops
the first for loop shall start with i=1:2:length(r) and from it x1 and y1 can be taken
the second loop shall start with j=2:2:length(r) and from it x2 and y2 can be taken
the problem i'm facing is that i want the program exist from the j loop once he take the values of x2 and y2 and go on with other operations after it and when it come back to it again i want the j to be as 4 but it always return the j value as 2 ...
Abdulla Aqeel
  1 Comment
Stephen23
Stephen23 on 15 May 2015
This is not enough information to know exactly what you re trying to achieve. Please explain the exact sequence that the loops would need to iterate over.
Can you please upload your code using the paperclip button. You will need to push both the Choose file and Attach file buttons.

Sign in to comment.

Answers (2)

Joseph Cheng
Joseph Cheng on 15 May 2015
with the very vague explanation i have no idea how you are coming back to a loop after breaking out of it. But i'll take a stab at it. You'll have to implement something like
startloopval = 1;
for ind = startloopval:10
startloopval = startloopval+1
end
which however you come back to that for loop you'll come back after the initialization of the starting value and it'll use whatever value you want.

James Tursa
James Tursa on 15 May 2015
I don't fully understand what you are trying to do, but I will say that in general if you want to change the loop index value inside the loop, a for loop is not the appropriate choice. Usually some form of while loop is better. E.g., this construct:
for j=2:2:length(r)
% Do some calculations
% change the value of j
end
is usually coded as something like this instead:
j = 2
while( j <= length(r) )
% Do some calculations
% change the value of j, or
% j = j + 2;
end

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!