This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Loops and Conditional Statements

Control flow and branching using keywords, such as if, for, and while

MATLAB Language Syntax

if, elseif, elseExecute statements if condition is true
forfor loop to repeat specified number of times
parforParallel for loop
switch, case, otherwiseExecute one of several groups of statements
try, catchExecute statements and catch resulting errors
whilewhile loop to repeat when condition is true
breakTerminate execution of for or while loop
continuePass control to next iteration of for or while loop
endTerminate block of code, or indicate last array index
pauseStop MATLAB execution temporarily
returnReturn control to invoking function


Conditional Statements

To determine which block of code to execute at run time, use if or switch conditional statements.

Loop Control Statements

To repeatedly execute a block of code, use for and while loops.