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

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 comentario

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.

Iniciar sesión para comentar.

Respuestas (2)

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.
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

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 15 de Mayo de 2015

Respondida:

el 15 de Mayo de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by