Skip to Main Content Skip to Search
Product Documentation

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

break | end | for | return | while

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS