O'Reilly logo

MATLAB® and Its Applications in Engineering: [Based on MATLAB 7.5 (R2007b)] by Manoj Kumar Sharma, Ashok Kumar Goel, Raj Kumar Bansal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required