Programming and Data Types |
The break
statement terminates the execution of a for
loop or while
loop. When a break
statement is encountered, execution continues with the next statement outside of the loop. In nested loops, break
exits from the innermost loop only.
The example below shows a while
loop that reads the contents of the file fft.m
into a MATLAB character array. A break
statement is used to exit the while
loop when the first empty line is encountered. The resulting character array contains the M-file help for the fft
program.
fid = fopen('fft.m','r'); s = ''; while ~feof(fid) line = fgetl(fid); if isempty(line) break end s = strvcat(s,line); end disp(s)
continue | try ... catch |