|LabVIEW 2015 Help|
|LabVIEW 2016 Help|
|LabVIEW 2017 Help|
|LabVIEW 2018 Help|
|LabVIEW 2019 Help|
A For Loop executes the section of code inside the loop, called a subdiagram, a set number of times. The count (N) terminal sets the number of times to repeat the subdiagram. One subdiagram repetition is called an iteration.
Use a For Loop any time you want an operation to occur a set number of times. For example, if you want to write a set number of measurements to a file, place the code that writes measurements to the file inside a For Loop. The numeric value you wire to the count terminal determines the number of times the writing operation occurs. After the For Loop executes the subdiagram for the number of iterations you set, the For Loop stops.
To stop a For Loop when a condition occurs,add a conditional terminal. If you add a conditional terminal, the For Loop stops when the condition occurs or when the loop finishes executing the number of iterations you set.
The For Loop does not pass values from one iteration to the next by default. To access data from the previous iteration and use it in the next iteration, add shift registers to the For Loop. For example, if you want to use the result of a mathematic operation in one iteration as the initial value for a mathematic operation in the next iteration, use shift registers.
When you wire an array to the input tunnel of a For Loop, the For Loop enables auto-indexing by default. When auto-indexing is enabled, the For Loop reads and processes one element in the array per loop iteration, rather than reading and processing the entire array each iteration. You can enable or disable auto-indexing depending on how you want the For Loop to process the data.
If rapid For Loop execution is crucial to the operation of a VI and the machine running the VI has multiple processors, enable parallel For Loop iterations, unless enabling parallel iterations produces an error or warning. When you enable parallel iterations, processors execute iterations simultaneously to improve performance.