Determining the execution order of a program by arranging its elements in a certain sequence is called control flow. Visual Basic, C, and most other procedural programming languages have inherent control flow because statements execute in the order in which they appear in the program. LabVIEW uses the Sequence Structure to obtain control flow within a dataflow framework. A Sequence Structure is an ordered set of frames that execute sequentially. A Sequence Structure executes frame 0, followed by frame 1, then frame 2, until the last frame executes. Only when the last frame completes does data leave the structure. There are two flavors of Sequence Structure: the Flat Sequence Structure and the Stacked Sequence Structure, shown in Figure 6.43 and Figure 6.44, respectively. These can both be found in the Programming>>Structures subpalette of the Functions palette. The two types of Sequence Structure are almost identical, having frames that look like frames of a film. The difference is that the frames of a Flat Sequence Structure are organized sequentially side-by-side and the frames of a Stacked Sequence Structure are organized sequentially in a stack, appearing similar to a Case Structure. Figure 6.43. Flat Sequence Structure Figure 6.44. Stacked Sequence Structure Regardless of appearance, either type of Sequence Structure (Flat or Stacked) executes code exactly in the same manner. In fact, you can easily convert one into the other by selecting from its pop-up menu, Replace with Stacked Sequence (to convert from Flat to Stacked) or Replace>>Replace with Flat Sequence (to convert from Stacked to Flat). Don't let the size advantage of the Stacked Sequence Structure lure you into thinking that it is a better choice than the Flat Sequence Structure. As we will soon find out, the use of Stacked Sequence Structures can lead to many negative side effects. Stacked Sequence Structures and Sequence Locals Are EvilOK, the title of this section is pretty harsh. Sequence Locals aren't really evilthey have no minds of their own. However, we want to be sure that you know to avoid using them or you may find yourself heading down the dark and dangerous path toward a VI full of spaghetti code. Let's take a look at the Stacked Sequence Structure and Sequence Locals, and then we will look at an example that shows why we should avoid them. Like the Case Structure, the Stacked Sequence Structure has only one frame visible at a timeyou must click the arrows at the top of the structure to see other frames, or you can click on the top display for a listing of existing frames, or pop up on the structure border and choose Show Frame . . . . When you first drop a Sequence Structure on the block diagram, it has only one frame; thus, it has no arrows or numbers at the top of the structure to designate which frame is showing. Create new frames by popping up on the structure border and selecting Add Frame After or Add Frame Before. There are some very important reasons why the Flat Sequence Structure is a better choice than the Stacked Sequence Structure:
Sequence Locals are evil because
Figure 6.49 and Figure 6.50 show the dramatic difference between the Flat Sequence Structure and the Stacked Sequence Structure. It is easy to see the difference in readability. Figure 6.49. A simple example using a Flat Sequence Structureclean!![]() Figure 6.50. A Stacked Sequence equivalent of our Flat Sequence Structure exampleyuck!![]() |