Reputation: 75
We cannot use continue function in functions in matlab. For example, the following is not allowed:
for ii = 1:5
function1(ii)
end
function function1(in)
if ii, continue; else, disp('hi'); end
end
Is there an alternative structure I should be using? Should I always just put the for loop inside the function? Would there be a reason not to put for loop inside the function?
@Peng Chen answers most of my answers. Yet, I wanted to add that the simple solution for MATLAB-specific problem was to use 'return' instead of 'continue' in the subfunction.
Upvotes: 0
Views: 200
Reputation: 61
Yes. For example:
for ii = 1:5
out=function1(ii);
if out,continue;end
end
function out=function1(in)
if in,out=1;else,out=0;disp('hi');end
end
Let the function1 deal with ii. Use return value of function1 to deal with the for loop.
Sorry for my poor English.
Upvotes: 2