Structures in LabVIEW: Loops, Case and Sequence Structures (original) (raw)

Tutorial 5 of LabVIEW covers the details of structures in LabVIEW. These structures include loops, cases, and sequence structures in LabVIEW. In our last tutorial, we saw how to form a weather station using LabVIEW and Arduino, which shows the ambient temperature and intensity of light on the front panel of LabVIEW. In previous tutorials, we worked on the basics of LabVIEW and its interfacing with Arduino. We used analog and digital read and write blocks, PWM, and controls. They were very basic functions of LabVIEW. In today’s tutorial, we will move to an advanced level and see how to use different structures. They help us iterate some code more than once. These functions give LabVIEW many extra powers as a programming language. We recommend checking out this getting started tutorial on LabVIEW.

We will discuss the following structures here in detail and get ourselves familiarized with their use and their power.

While Loop Structure in LabVIEW

The While loop structure keeps running a program placed inside it until a stop condition is satisfied. We use a loop structure to keep a program running until we press or click a STOP button. The While loop structure keeps on running and generating different values until the program satisfies the STOP condition, which in this case generates a value equal to 50.

For Loop Structure in LabVIEW

A for-loop structure repeats the program a specific number of times. In the for loop, we have “N”,” which is the count terminal, and i, which is the iteration terminal. The value of “I” changes from 0 to N-1 each time the loop executes.

Auto-Indexing a For Loop

When working with arrays, it is often useful to work with each element in the array one at a time, one after the other. LabVIEW will do this automatically whenever we wire an array to an input tunnel in a For Loop if we enable the tunnel for indexing. This is called auto-indexing the For Loop.

Case Structure

In LabVIEW, case structures allow specific programming parts to run depending on the value of a variable. We can find case structure in LabVIEW’s structure palette.

Sequence Structure

A sequence structure is useful when we require the execution of some program in sequential order. In LabVIEW, we cannot always control the order of execution. When the next calculation depends on the previous one, we are sure it will occur in the correct order. But when calculations are done in parallel, we cannot control the order in which they take place. A sequence structure is used to force calculations to take place in a defined sequence.

Conclusion

In this article, we have discussed the following topics:

Related Articles

You may also like to read: