Documentation Center

  • Trial Software
  • Product Updates

continue

Pass control to next iteration of for or while loop

Syntax

continue

Description

continue temporarily interrupts the execution of a program loop, skipping any remaining statements in the body of the loop for the current pass. The continue statement does not cause an immediate exit from the loop as a break or return statement would do, but instead continues within the loop for as long as the stated for or while condition holds true.

A continue statement in a nested loop behaves in the same manner. Execution resumes at the for or while statement of the loop in which the continue statement was encountered, and reenters the loop if the stated condition evaluates to true.

Examples

Count the number of lines of code in the file magic.m, skipping all blank lines and comments.

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
fprintf('%d lines\n',count);
fclose(fid);

See Also

| | | |

Was this topic helpful?