loop stop executing after executing nested if statement

I wrote a nested loop like below:

   for i = 1:m
      do something;
      for j = 1:n 
        do something;
        if conditionIsTrue
          do something;  %without continue or break
        end
      end
    end

But the loop ends after the first time the condition in if statement is executed and return incorrect result, I tried to modify the code as below:

    for i = 1:m
      do something;
      for j = 1:n 
        do something;
        if conditionIsTrue
          do something;  
          continue
        else
          continue
        end
      end
    end
The problem's still there. How can I deal with this problem?

1 comentario

turns out I tried to iterate through a column vector, hence the loop stops after the first element.

Iniciar sesión para comentar.

Respuestas (1)

for i = 1:m
do something;
for j = 1:n
do something;
if conditionIsTrue
do something;
else
continue
end
end
end

4 comentarios

Doesn't work.
what are your operations?
thx problem sovled.
Accept the answer so that other people know the question is solved

Iniciar sesión para comentar.

Categorías

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

Productos

Preguntada:

el 21 de Oct. de 2018

Comentada:

el 24 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by