| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
Ports & Subsystems/For Iterator Subsystem
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 output of a For Iterator subsystem can not be a function-call signal. Simulink software will display an error message if the simulation is run or the diagram updated.
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:
in+1 = in +1
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. |
The following rules apply to the data type of the number of iterations (N) input port:
The input port accepts data of mixed numeric types.
If the input port value is noninteger, it is first truncated to an integer.
Internally, the input value is cast to an integer of the type specified for the iteration variable output port.
If no output port is specified, the input port value is cast to type int32.
If the input port value exceeds the maximum value of the output port's type, it is truncated to that maximum value.
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.
It can appear only if the iteration variable output port is enabled.
The data type of the iteration variable input port is the same as the data type of the iteration variable output port.

Set this field to 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.
If you set this field to internal, the value of the Iteration limit 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.
Set the number of iterations by specifying a number or a named constant. This field appears only if you selected internal for the Iteration limit source field. This parameter supports storage classes. You can define the named constant in the base workspace of the Model Explorer as a Simulink.Parameter object of the built-in storage class Define (custom) type. For more information, see Applying a Custom Storage Class to a Parameter in the Real-Time Workshop Embedded Coder documentation.
This option can be selected only if you select the Show iteration variable option. If you select this option, the For Iterator block displays an additional input for connecting an external iteration variable source. The value of the input at the current iteration is used as the value of the iteration variable at the next iteration.
If you select this check box, the For Iterator block outputs its iteration value.
If you set this field to Zero-based, the iteration number starts at zero. If you set this field to One-based, the iteration number starts at one.
Set the type for the iteration value output from the iteration number port to double, int32, int16, or int8.
Direct Feedthrough | No |
Sample Time | Inherited from driving blocks |
Scalar Expansion | No |
Dimensionalized | No |
Zero Crossing | No |
![]() | Fixed-Point State-Space | For Iterator Subsystem | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |