Pass control to next iteration of
continue passes control to the next iteration
It skips any remaining statements in the body of the loop for the
current iteration. The program continues execution from the next iteration.
continue applies only to the body of the
loop where it is called. In nested loops,
remaining statements only in the body of the loop in which it occurs.
Display the multiples of 7 from 1 through 50. If a number is not divisible by 7, use
continue to skip the
disp statement and pass control to the next iteration of the
for n = 1:50 if mod(n,7) continue end disp(['Divisible by 7: ' num2str(n)]) end
Divisible by 7: 7 Divisible by 7: 14 Divisible by 7: 21 Divisible by 7: 28 Divisible by 7: 35 Divisible by 7: 42 Divisible by 7: 49
Count the number of lines of code in the file
magic.m. Skip blank lines and comments using a
continue skips the remaining instructions in the
while loop and begins the next iteration.
fid = fopen('magic.m','r'); count = 0; while ~feof(fid) line = fgetl(fid); if isempty(line) || strncmp(line,'%',1) || ~ischar(line) continue end count = count + 1; end count
count = 31
continue statement skips
the rest of the instructions in a
and begins the next iteration. To exit the loop completely, use a
continue is not defined outside
while loop. To
exit a function, use