C:
for( curVal = startVal; curVal <= endVal; curVal += step) {...}
Fortran:
do curVal = startVal, endVal, step...enddo
When For receives data from upstream or from a widget change, it begins a loop iteration. "Current Value" is initialized to "Start Value" and input data is taken from the "initial" inputs. While "Current Value" is less than or equal to "End Value", the input data is sent out on the "loop" outputs. When data returns from the loop, For takes input from the "loop" inputs and increments "Current Value" by "Step". When "Current Value" becomes greater then "End Value", the input data is sent out on the "final" outputs.
The termination condition (the relationship between the current value and the end value) may be altered via a menubar item. If the end value is less than the start value, the termination condition and the step value adjust accordingly.
For acts as a data switcher, cycling data values through the loop while the iteration condition is true, and switching data values out of the loop when the iteration condition becomes false. Since the input data is not operated on, the ports are defined as type cxGeneric, allowing data of any type ports to be connected to it.
The For module provided defines 4 loop variables. For example, "Initial Value 0" and "LoopIn Value 0" are the initial and loop inputs, and "LoopOut Value 0", and "Final Value 0" are the loop and final outputs for a single loop variable.
It is possible to customize the For module to accept more loop variables or to accept particular types. Copy /usr/explorer/modules/For.mres to a local directory, rename it myFor.mres and run mbuilder(1E) on myFor. Under the Build/Options menu, set the alternate executable to be /usr/explorer/modules/For.
The correspondence between input ports and output ports and a loop variable is defined by the name. Initial input ports begin with the string "Initial", looping input ports begin with "LoopIn", looping outputs begin with "LoopOut", and final outputs begin with "Final". The module looks for input and output ports whose names begin with these key words are the same after the key word. It must find at least one input port and at least one output port with the same suffix to create a match for a loop variable. That is, defining an initial input with no corresponding loop input is permitted.
You may define any number of loop variables in this way, using more descriptive port names. You may also change the port types of the loop variables to insure that your new module is used correctly.
Port: Initial Value 0
Type: Generic
Optional: This port is optional
Port: Initial Value 1
Type: Generic
Optional: This port is optional
Port: Initial Value 2
Type: Generic
Optional: This port is optional
Port: Initial Value 3
Type: Generic
Optional: This port is optional
Initial values.
Port: LoopIn Value 0
Type: Generic
Optional: This port is optional
Port: LoopIn Value 1
Type: Generic
Optional: This port is optional
Port: LoopIn Value 2
Type: Generic
Optional: This port is optional
Port: LoopIn Value 3
Type: Generic
Optional: This port is optional
Loop return values.
Port: Start Value
Type: Slider
Initial value of loop index.
Port: End Value
Type: Slider
Final value of loop index.
Port: Step Value
Type: Slider
Increment added to loop index at the end of each iteration.
Port: Current Value
Type: Text
The current value of the loop index.
Port: Refire
Type: Button
Forces the loop to be run again.
Port: Condition
Type: Slider
Zero means the loop will continue while the current value is less
than or equal to the end value.
One means the loops will continue while the current value is less
than the end value.
These conditions are "greater than or equal" and "greater than"
respectively if the end value is less than the start value, that is,
the loop counts negatively.
Port: Final Value 0
Type: Generic
The value of "LoopIn Value 0" after the final loop
iteration.
Port: Final Value 1
Type: Generic
The value of "LoopIn Value 1" after the final loop
iteration.
Port: Final Value 2
Type: Generic
The value of "LoopIn Value 2" after the final loop
iteration.
Port: Final Value 3
Type: Generic
The value of "LoopIn Value 3" after the final loop
iteration.
Port: LoopOut Value 0
Type: Generic
Pass-through data from "Initial Value 0" (initially) and
"LoopIn Value 0" (on subsequent loop iterations).
Port: LoopOut Value 1
Type: Generic
Pass-through data from "Initial Value 1" (initially) and
"LoopIn Value 1" (on subsequent loop iterations).
Port: LoopOut Value 2
Type: Generic
Pass-through data from "Initial Value 2" (initially) and
"LoopIn Value 2" (on subsequent loop iterations).
Port: LoopOut Value 3
Type: Generic
Pass-through data from "Initial Value 3" (initially) and
"LoopIn Value 3" (on subsequent loop iterations).