Within any program, you can define sections of code that either repeat in a loop or conditionally execute. Loops use a for or while keyword, and conditional statements use if or switch . Additional keywords provide finer control over the program flow.
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 |