Create an iterate loop
An iterate loop processes multiple elements in sequence. For example, you can use an iterate loop to compute the product of an array of values connected to an iteration target input port.
Add an
iteratenode to the graph.Optionally, you can create any ports you want by drawing connections to the New Port icon. Right-click on a port to rename it or make other changes.
Enter the compound and create the subgraph for the computation that you want to perform in the loop.
- If you want your compound to iterate over the items in an array, right-click on the input array port and choose Set Port Iteration Target > true. On the Nth iteration of the loop, the values of any input iteration targets are the Nth items in the connected arrays.
- If you have set one or more input iteration targets, then it is safe to delete the
max_iterationsport. By doing this, you do not need to connect the size of the array to ensure that all items are processed. - You can also set output ports as iteration targets. The value is an array where the Nth item is the result of the Nth iteration.
- You do not need to have an input array port set as an iteration target — you can also use the
max_iterationsport to control the number of iterations directly. - To pass an intermediate value such as a partial sum from one iteration to the next, use a pair of "state" ports. State ports consist of an input and output port that are matched so that the output value is carried forward as the input to the next iteration of the loop. To create a pair of state ports, right-click on a port of the compound's
inputoroutputnode, expand the Set Port State menu, and select a matching port. Optionally, you can initialize the input value for the first iteration by connecting or setting a value on the outside of the loop compound. - All outputs from an
iterateloop must be either an iteration target or a state port.
