MATLAB Function Reference
  Go to function:
    Search    Help Desk 
for    Examples   See Also

Repeat statements a specific number of times

Syntax

Description

The general format is

The columns of the expression are stored one at a time in the variable while the following statements, up to the end, are executed.

In practice, the expression is almost always of the form scalar : scalar, in which case its columns are simply scalars.

The scope of the for statement is always terminated with a matching end.

Examples

Assume n has already been assigned a value. Create the Hilbert matrix, using zeros to preallocate the matrix to conserve memory:

Step s with increments of -0.1

Successively set e to the unit n-vectors:

The line

has the same effect as

except j is also set here.

See Also

break       Terminate execution of for or while loop

end         Terminate for, while, switch, and if statements and indicate the last index

if          Conditionally execute statements

return      Return to the invoking function

switch      Switch among several cases based on expression

while       Repeat statements an indefinite number of times



[ Previous | Help Desk | Next ]