Main Content

for

for loop to repeat specified number of times

Syntax

for index = values
   statements
end

Description

example

for index = values, statements, end executes a group of statements in a loop for a specified number of times.

If a colon, : operation with fi objects is used as the index, then the fi objects must be whole numbers.

Refer to the MATLAB® for reference page for more information.

Examples

collapse all

Use a fi object as the index of a for loop.

a = fi(1,0,8,0);
b = fi(2,0,8,0);
c = fi(10,0,8,0);

for x = a:b:c
 x
end
x = 
     1

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0
x = 
     3

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0
x = 
     5

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0
x = 
     7

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0
x = 
     9

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2014b