Skip to main content

11.15) Control Statements


Let's introduce and remind ourselves of some control statements that are used within flow control.

break - Terminates execution of a for loop or while loop. Statements after the "break" statement are not executed. If the "break" is within a nest loop, then "break" exits only the immediate loop, where it sits.

continue - This passes control to the next iteration of the for loop or while loop. It doesn't cause an exit from the loop itself, unlike the "break" statement.

end - Terminates an "if", "switch", "for", "while" or "try" statement. Without an "end", Matlab will wait for further input (if code is entered within the command window) or produce an error (if within a script or function).

pause - Halts execution until the user presses a key or until a specified amount of time has passed.