7.2. Loops
The loops are classified depending upon the manner in which the iterations in a program are controlled. There are two forms of loops: (i) for and (ii) while. In case of for loop, the number of repetitions is already known, whereas in while loop, execution is repeated until the condition is satisfied.
7.2.1. for Loop
The for loop control structure is used for unconditional looping. In this control structure, a group of statements, say ‘n’ in number, are executed repeatedly for a fixed specified number of times, which is known before the loop starts and is decided by an index. The syntax of for statement is given as follows:
for index = initial value : increment : last value statement 1; statement 2; . . . statement n; end; next statement ...
Get MATLAB® and Its Applications in Engineering: [Based on MATLAB 7.5 (R2007b)] now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.