English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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 Number | Types of Loops and Descriptions |
---|---|
1 | while loop Repeat a statement or a group of statements while a given condition is true. It tests the condition before executing the loop body. |
2 | for loop Execute a statement sequence multiple times and simplify the code for managing loop variables. |
3 | Nested Loops One or more loops can be used within any other loop. |
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 Number | Control Statements and Descriptions |
---|---|
1 | break statement Terminates the loop statement and immediately transfers execution to the statement after the loop. |
2 | continue statement It makes the loop skip the rest of its body and immediately retest its status before repeating. |