Loops and Conditional Statements
Control flow and branching using keywords, such as
if
,
for
, and while
MATLAB Language Syntax
if, elseif, else | Execute statements if condition is true |
switch, case, otherwise | Execute one of several groups of statements |
for | for loop to repeat specified number
of times |
while | while loop to repeat when condition
is true |
try, catch | Execute statements and catch resulting errors |
break | Terminate execution of for or while loop |
return | Return control to invoking script or function |
continue | Pass control to next iteration of for or while loop |
pause | Stop MATLAB execution temporarily |
parfor | Parallel for -loop |
end | Terminate block of code or indicate last array index |
Topics
- Conditional Statements
To determine which block of code to execute at run time, use
if
orswitch
conditional statements. - Loop Control Statements
To repeatedly execute a block of code, use
for
andwhile
loops.