| Simulink Reference | ![]() |
Repeatedly execute the contents of a subsystem at the current time step until an iteration variable exceeds a specified iteration limit.
Library
Ports & Subsystems/For Iterator Subsystem
Description
The For Iterator block, when placed in a subsystem, repeatedly executes the contents of the subsystem at the current time step until an iteration variable exceeds a specified iteration limit. You can use this block to implement the block diagram equivalent of a for loop in the C programming language.
The block's parameter dialog allows you to specify the maximum value of the iteration variable or an external source for the maximum value and an optional external source for the next value of the iteration variable. If you do not specify an external source for the next value of the iteration variable, the next value is determined by incrementing the current value:
The model in the following figure uses a For Iterator block to increment an initial value of zero by 10 over 20 iterations at every time step.
The following figure shows the result.
The For Iterator subsystem in this example is equivalent to the following C code.
sum = 0; iterations = 20; sum_increment = 10; for (i = 0; i < iterations; i++) { sum = sum + sum_increment; }
| Note Placing a For Iterator block in a subsystem makes it an atomic subsystem if it is not already an atomic subsystem. |
Data Type Support
The following rules apply to the data type of the number of iterations (N) input port:
int32.
Data output for the iterator value can be selected as double, int32, int16, or int8 in the Block Properties dialog.
The following rules apply to the iteration variable input port.
Parameters and Dialog Box
reset if you want the states of the For subsystem to be reinitialized before the first iteration at each time step. Otherwise, set this field to held (the default) to make sure that these subsystem states retain their values from the last iteration at the previous time step.
internal, the value of the Number of iterations field determines the number of iterations. If you set this field to external, the signal at the For Iterator block's N port determines the number of iterations. The iteration limit source must reside outside the For Iterator subsystem.
internal for the Source of number of iterations field.
double, int32, int16, or int8.
Characteristics
| Direct Feedthrough |
No |
| Sample Time |
Inherited from driving blocks |
| Scalar Expansion |
No |
| Dimensionalized |
No |
| Zero Crossing |
No |
| Fixed-Point State-Space | For Iterator Subsystem | ![]() |
© 1994-2005 The MathWorks, Inc.