

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


10/31/21, 4:20 PM MATLAB - Loop Types https://www.tutorialspoint.com/matlab/matlab_loops.htm 1/
There may be a situation when you need to execute a block of code several number of times. InThere may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially. The first statement in a function is executed first,general, statements are executed sequentially. The first statement in a function is executed first, followed by the second, and so on.followed by the second, and so on. ProgrammingProgramming languageslanguages^ provideprovide variousvarious^ controlcontrol^ structuresstructures^ thatthat^ allowallow forfor moremore^ complicatedcomplicated execution paths.execution paths. A loop statement allows us to execute a statement or group of statements multiple times andA loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages −following is the general form of a loop statement in most of the programming languages − MATLAB provides following types of loops to handle looping requirements. Click the following linksMATLAB provides following types of loops to handle looping requirements. Click the following links to check their detail −to check their detail −
10/31/21, 4:20 PM MATLAB - Loop Types https://www.tutorialspoint.com/matlab/matlab_loops.htm 2/ Sr.No. Sr.No. Loop Type & DescriptionLoop Type & Description 11 while loopwhile loop Repeats a statement or group of statements while a given condition is true. It tests the Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. condition before executing the loop body. 22 for loopfor loop Executes a sequence of statements multiple times and abbreviates the code that Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable. manages the loop variable. 33 nested loopsnested loops You can use one or more loops inside any another loop. You can use one or more loops inside any another loop.
Loop control statements change execution from its normal sequence. When execution leaves aLoop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.scope, all automatic objects that were created in that scope are destroyed. MATLAB supports the following control statements. Click the following links to check their detail.MATLAB supports the following control statements. Click the following links to check their detail. Sr.No. Sr.No. Control Statement & DescriptionControl Statement & Description 11 break statementbreak statement Terminates the Terminates the looploop statement and transfers execution to the statement immediatelystatement and transfers execution to the statement immediately following the loop. following the loop. 22 continue statementcontinue statement Causes the loop to skip the remainder of its body and immediately retest its condition Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. prior to reiterating.