MATLAB Function Reference    
break

Terminate execution of a for loop or while loop

Syntax

Description

break terminates the execution of a for loop or while loop. In nested loops, break exits from the innermost loop only.

Remarks

If you use break outside of a for or while loop in a MATLAB script or function, break terminates the script or function at that point.

If break is executed in an if, switch-case, or try-catch statement, it terminates the statement at that point.

Examples

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.

See Also

end, for, return, while


 box brighten