📅  最后修改于: 2021-01-07 02:19:03             🧑  作者: Mango
Continue语句在for或while循环中工作,并将控制权传递给循环的下一个迭代。
Continue
以下是在MATLAB中使用continue语句的要点:
% program to print all numbers divisible by 3 and skip remaining
a = (1:4:50); % creates row vector from 1 to 50 with a step of 4
for k = 1:numel(a)
if rem(a(k),3)
continue
end
disp(a(k))
end
输出:
9
21
33
45
% program to find number which is divisible by all numbers from 2 to 9
v = [2,3,4,5,6,7,8,9];
min = 1;
max = 10000;
for m = min : max
if mod(m,v(1))
continue
else
if mod(m,v(2))
continue
else
if mod(m,v(3))
continue
else
if mod(m,v(4))
continue
else
if mod(m,v(5))
continue
else
if mod(m,v(6))
continue
else
if mod(m,v(7))
continue
else
if mod(m,v(8))
continue
else
disp(['divisible by all :' num2str(m)])
end
end
end
end
end
end
end
end
end
disp('....')