Main Content

For Iterator

Control block for for-iterator subsystem

Description

The For Iterator block, when placed in a Subsystem block, repeats the execution of a subsystem during the current time step until an iteration variable exceeds the specified iteration limit. You can use this block to implement the block diagram equivalent of a for loop in a programming language.

The output of a For Iterator Subsystem block cannot be a function-call signal. Simulink® displays an error message when the model updates.

Ports

Input

expand all

  • The input port accepts data of mixed numeric types.

  • If the input port value is non-integer, 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 type, the overflow saturates.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Output

expand all

Selecting the Show iteration variable parameter check box adds an output port to this block.

Data Types: double | int8 | int16 | int32 | uint8 | uint16 | uint32

Parameters

expand all

Select how to handle block states between time steps.

held

Hold block states between time steps. Block state values persist across time steps.

reset

Reset block states to their initial values at the beginning of each time step and before the first iteration loop.

Programmatic Use

Block Parameter: ResetStates
Type: character vector
Values: 'held' | 'reset'
Default: 'held'

Select source for number of iterations.

internal

Value of the Iteration limit parameter determines the number of iterations.

external

Value of the signal at the N port determines the number of iterations. The signal source must reside outside the For Iterator Subsystem block.

Dependencies

Selecting internal displays and enables the Iteration limit parameter. Selecting external adds an input port labeled N.

Programmatic Use

Block Parameter: IterationSource
Type: character vector
Values: 'internal' | 'external'
Default: 'internal'

Specify the number of iterations. 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.

5

Iterate blocks in the For Iterator Subsystem block 5 times.

integer

Specify an integer or a named constant variable.

Dependencies

To enable this parameter, select internal from the Iteration limit source drop-down list.

Programmatic Use

Block Parameter: IterationLimit
Type: character vector
Values: '5' | '<integer>'
Default: '5'

Control display of an input port.

off

Remove input port.

on

Add input port labeled Next_i for connecting to 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.

Dependencies

To enable this parameter, select the Show iteration variable parameter which also displays an output port labeled 1:N.

Programmatic Use

Block Parameter: ExternalIncrement
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Control the display of an output port with the current iterator value for a loop.

on

Add output port labeled 1:N to the For Iterator block.

off

Remove output port.

Dependencies

Selecting this parameter enables the Set next i (iteration variable) externally parameter.

Programmatic Use

Block Parameter: ShowIterationPort
Type: character vector
Value: 'on' | 'off'
Default: 'on'

Select an initial iteration number of 0 or 1.

One-based

Iteration number starts at one.

Zero-based

Iteration number starts at zero.

Programmatic Use

Block Parameter: IndexMode
Type: character vector
Values: 'One-based' | 'Zero-based'
Default: 'One-based'

Set the data type for the iteration value output from the iteration number port. The maximum allowable value for the iteration variable is determined by the Index mode and Iteration variable data type parameters. For example, if you set Index mode as One-based and Iteration variable data type as int8, the maximum allowable value for the iteration variable is 27-1. However, if you set Iteration variable data type as uint32 or double, the maximum allowable value for the iteration variable is restricted to the maximum positive value for signed 32-bit integer (int32). For more information about range of values for different integer classes, see Integers.

int32

Set data type to int32.

uint32

Set data type to uint32.

int16

Set data type to int16.

uint16

Set data type to uint16.

int8

Set data type to int8.

uint8

Set data type to uint8.

double

Set data type to double.

Programmatic Use

Block Parameter: IterationVariableDataType
Type: character vector
Value: 'int32' | 'uint32'|'int16' | 'uint16'|'int8' | 'uint8'|'double'
Default: 'int32'

Version History

Introduced before R2006a