Control Flow

Conditional statements, loops, branching


MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

To convert a MuPAD notebook file to a MATLAB live script file, see convertMuPADNotebook. MATLAB live scripts support most MuPAD functionality, although there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

MuPAD Functions

%ifConditional creation of code by the parser
break, _breakTerminate a loop or a Case switch prematurely
case, of, otherwise, end_case, _caseSwitch statement
endClose a block statement
for, from, to, step, end_for, _for_in, downto, _for_downtoFor loop
if, then, elif, else, end_if, _ifIf-statement (conditional branch in a program)
next, _nextSkip a step in a loop
repeat, until, end_repeat, _repeat“repeat” loop
while, end_while, _while“while” loop
returnExit a procedure


Conditional Control

You can execute different groups of statements depending on particular conditions.


The for loop repeats a group of statements for a fixed number of iterations.

Shortcut for Closing Statements

As a shortcut for a closing statement, use the end command.