Labview For loop, while loop, case structure
LabVIEW is a graphical programming language and its development environment is created by National Instruments (NI). It is commonly used for data acquisition, instrument control, and industrial automation. LabVIEW allows users to visually design programs using a graphical user interface (GUI). Let us learn for loop, while loop and case structure in labview like any other programming languages.
More than often, we would like an action to repeat until a condition is satisfied; for example, we may want to accept data from the user until the variable provided is of a particular value. At which point we will stop the loop so that it will not process any data further. This is the application where while loop is used.
A While Loop executes the functions it contains until the conditional terminal receives a specific Boolean value either 'True' or 'False'.
This conditional terminal will Stop If True(SYMBOL: red circle in square ) by default. Another terminal is conditional terminal referred as Continue If True, is also available by right click on the conditional terminal. Hence while loop can be used based on boolean control (true or false).
There is another terminal called the iteration terminal, which is an output terminal (SYMBOL: i letter in blue lined square ). Every run of the While Loop is considered as 1 iteration. This terminal as mentioned returns the no. of iterations completed during while loop execution and after the execution. The iteration terminal initializes with zero during start. Hence after first iteration it returns zero.
A For Loop similar to While Loop is also a loop structure. The main difference is that For Loop performs as many iterations as provided by its count terminal (SYMBOL: N letter in blue lined square).
The for loop conditional terminal can be inserted by right clicking it. This terminal takes a boolean value. It instructs the for loop to execute the next iteration or break the for loop without executing the next iterations. This is shown in the figure. Download the example labview VI mentioned below which covers for loops without and with a conditional terminal.
You place the Case structure on the block diagram by selecting it from the
Structures subpalette of the Functions palette. You can either enclose
nodes with the Case structure or drag nodes inside the structure.
The Case structure is same as conventional if...then...else statements used in text-based programming languages. Only one case executes based on the value wired to the selector terminal. The selector terminal can be numeric or boolean or string. If the data type is Boolean, the structure has a True case and a False case. The case structure can have up to 231-1 cases in numeric or string data types are used.
One can create boolean case structure as well as numeric Case structure. Above figure depicts boolean operations and below figure depicts numeric operations.
REMEMBER FOLLOWING POINTS for programming using case structure:
➨Connect the case port, it is must.
➨Decide and program the case condition.
➨More cases can be added by right clicking the existing one.
➨All the terminals should be connected for all the cases of the structure.
Download Labview Source codes of this loops and case structure
Similar posts on Labview programming
Labview data types Creating SubVI Creating Array and Array operations Cluster concepts in labview Various plots in labview File I/Os For loop,while loop and case structure Local variable vs Global variable concepts