![labview while loop labview while loop](https://0.academia-photos.com/attachment_thumbnails/49796010/mini_magick20190130-15347-4zlixw.png)
Wire the output of the Equal? function to the Stop Condition terminal. Wire one of the inputs to the wire on the output of the increment node, and create a constant off of the other input. Right-click on the block diagram and select Equal? from the Comparison palette. This function tests the equality of two values. To find this information and tell the loop to stop, we will need an Equal? function. Our stop condition in this case will be when the count reaches 10. The loop will now count upward from 1, but we still need a stop condition for the loop. Place the indicator to the right of the increment node by right-clicking on the wire and select Create > Indicator. This indicator will show us the count from 1 to 10 as the loop executes. For that we will need an indicator on the inside of the loop, but after the increment node. Remember, LabVIEW reads left to right, so after the increment node adds 1 to the value of the previous iteration, we want to see that output. An increment node will appear on the wire. Right-click on the wire and select Insert > Numeric Palette > Increment. Wire the left terminal of the shift register to the right terminal on the inside of the loop. The shift register will change color to reflect the data type (orange for double precision in this case). Wire the constant to the left edge of the shift register. Right-click, select DBL constant from the Numeric palette and place it on the block diagram. To begin our count, we will need to provide an initial value to the shift register. The terminals are black because there is no data type assigned to the shift register. Values feed into the right terminal when the loop runs an iteration, the left terminal stores the value from the previous iteration. To use a shift register, right-click on either the right edge or the left edge of the loop and select Add Shift Register.Ī pair of terminals will appear on either edge of the loop. This is the method to use when data from the previous loop iteration is needed for the next iteration.
![labview while loop labview while loop](https://www.ni.com/images/gettingstarted/neutral/lv_exe_13.gif)
To use the While loop to count to 10, we will need to use a shift register, which functions somewhat like a variable whose value is reassigned with every loop iteration. This determines when and how the loop will stop. The stop condition terminal does have to be wired in order to run the program. It contains the loop count starting with 0, so the first time the loop runs the iteration terminal will output 0, the second time it will output 1, and so on. The iteration terminal does not have to be wired to anything. The While loop has two more parts to it: the iteration terminal and the stop condition terminal.
#Labview while loop code#
The code that sits inside the loop structure is the code that executes while the loop is running. Click and drag to size it, then release the mouse button to place it on the block diagram. On the block diagram, right-click and select While Loop from the Structures palette. Open LabVIEW and CTRL+N to create a new VI. This loop is good for extracting information contained in arrays, for example, where the size of the array determines the number of times the loop will run.įor this post we will use both types of loop to count to 10 in order to demonstrate how each type operates. There must always be a stop condition, but typically that condition is simply a stop button.įor loops, by contrast, will only run a set amount of times. Common uses for this type of loop include waiting on user input or running a process until it finishes. While loops will run indefinitely until a condition is met. Each type functions in a different fashion, so use cases for each will differ. The two types of loops used in LabVIEW are While loops and For loops. The introduction of loops is where basic programming gets a little more fun as this is the introduction to automation.