MATLAB: Can I ask Matlab to run from a previous line

edit and continueif statementloops

I am running an if loop, and I would like my else condition to return me to line 3 in my code, which is the line just before this loop starts. Is it possible to do this? If not, how can I run a loop which continues to run until a certain condition is fulfilled?

Best Answer

If what you want to do is "is repeat the line before the loop and then go through 1 more iteration of the loop." then put the while loop inside a for loop
for k = 1 : 2
a=10; % Some "line before the loop"
while someCondition
% Code that you want to do... then....
b = 20; % Whatever code you want to do.
% Now, at the bottom of the loop, don't let it do
% more than 1 iteration if k == 2
if k >= 2
break;
end
end
end