This can happen for a couple of scenarios.
- First, if the For Loop has a zero wired to the count (N) terminal, any information that is passed through it will be lost. This is due to the inside of the loop not executing, so the data cannot be passed on to the output terminal of the For Loop. This effectively causes the data that is provided to the For Loop's input tunnels to be lost. For example, the following snippet passes a numeric control and an initialized array to a For Loop configured to execute zero times. The two outputs will be uninitialized due to the data flow break in the loop:
- Secondly, You can also lose data from an array when executing the For Loop fewer times than the amount of initialized array elements. For example, if you have an array of six numbers as an input to an array set up to execute three times like the below snippet, the output array will only keep the first three numbers:
To preserve data, change the tunnel to a shift register. This shift register creates a memory allocation for the data, allowing it to be preserved at the For Loop's output, even if the loop is configured to execute zero times. To change a tunnel to a shift register, right-click on the input tunnel
and select Replace with Shift Register
. If the iteration count of the For Loop is determined from an auto-indexing array or file, make sure the size is not zero to prevent any data loss.