Simulink Reference Previous page   Next Page
While Iterator

Repeatedly execute the contents of a subsystem at the current time step while a condition is satisfied.

Library

Ports & Subsystems/While Subsystem

Description


The While Iterator block, when placed in a subsystem, repeatedly executes the contents of the subsystem at the current time step while a specified condition is true.

You can use this block to implement the block-diagram equivalent of a C program while or do-while loop. In particular, the block's While loop style parameter allows you to choose either of the following while loop modes:

The While Iterator block can optionally output the current iteration number, starting at 1. The following example uses this capability to compute N, where N is the first N integers whose sum is less than 100.

This example is the diagrammatic equivalent to the following pseudocode.

Data Type Support

Acceptable data inputs for the condition ports are any type supported by Simulink, as well as any fixed-point type, that includes a 0 value. For a discussion on the data types supported by Simulink, refer to Data Types Supported by Simulink in the Using Simulink documentation.

The While Iterator block's optional output port can output any of the following data types: double, int32, int16, or int8.

Parameters and Dialog Box

Maximum number of iterations
The maximum number of iterations allowed. Use a value of -1 to allow any number of iterations as long as the while condition input is true.
While loop style
Specifies the type of while loop implemented by this block. See the preceding block description for more information.
States when starting
Set this field to reset if you want the iterator block to reset the states of the blocks in the while subsystem to their initial values at the beginning of each time step (i.e., before executing the first loop iteration in the current time step). To cause the states of blocks in the subsystem to persist across time steps, set this field to held (the default).
Show iteration number port
If this check box is selected (the default), the While Iterator block outputs its iteration value. This value starts at 1 and is incremented by 1 for each succeeding iteration.
Output data type
If the Show iteration number port check box is selected (the default), this field is enabled. Use it to set the data type of the iteration number output to int32, int16, int8, or double.

Characteristics

Direct Feedthrough
No
Sample Time
Inherited from driving block
Scalar Expansion
No
Dimensionalized
No
Zero Crossing
No


Previous page  Variable Transport Delay While Iterator Subsystem Next page

Learn more about the latest releases of MathWorks products:

 © 1994-2009 The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS