MATLAB: How to skip an iteration in a for-loop

for looploopskip iteration

Hi, i have a for-loop and at the end of each iteration I want to check if a certain condition holds, if so, the loop is supposed to skip the next iteration. I tried it the (for me) obvious way:
for j=1:h
...do some interesting stuff...
if (z2>=f+tar(j+1)+1)
j=j+1;
end
end
it sets j to j+1 when it's supposed to but that doesn't effect the main for-loop at all. Where is my mistake? I could probably use a while-loop instead but it's supposed to be a for-loop… Thank you

Best Answer

Use the continue command.
If you want to break out of the loop entirely (based upon some condition), use the break command.