English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Loop Statements in MATLAB

In some cases, you need to execute a code block multiple times. Usually, statements are executed in order. The first statement in the function is executed first, then the second, and so on.

Programming languages provide various control structures that allow more complex execution paths.

Loop statements allow us to execute a statement or a group of statements multiple times. Here is the general form of loop statements in most programming languages.-

MATLAB provides the following types of loops to handle loop requirements. Click the following links to view their details.-

Serial NumberTypes of Loops and Descriptions
1while loop

Repeat a statement or a group of statements while a given condition is true. It tests the condition before executing the loop body.

2for loop

Execute a statement sequence multiple times and simplify the code for managing loop variables.

3Nested Loops

One or more loops can be used within any other loop.

Loop control statements

Loop control statements change the execution order from its normal sequence. When execution leaves the scope, all automatic objects created in that scope will be destroyed.

MATLAB supports the following control statements. Click the following links to view their details.

Serial NumberControl Statements and Descriptions
1break statement

Terminates the loop statement and immediately transfers execution to the statement after the loop.

2continue statement

It makes the loop skip the rest of its body and immediately retest its status before repeating.