Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 36 ยท Dataflow and Structures

Case and Sequence Structures

Branch in LabVIEW with Case structures (Boolean, integer, string, enum), the Select function, default cases, and order with flat sequence structures.

Programs make decisions. In LabVIEW, the main decision-maker is the Case structure: a stack of diagrams where exactly one runs, chosen by a selector value. The Select function handles tiny decisions, and the flat sequence structure controls order. This lesson describes how each behaves in the real product, and models them with JavaScript stand-ins; LabVIEW itself is not available on this site.

The Case structure

Find it in Programming > Structures. It looks like a box with a selector label at the top, showing the name of the visible case, with arrows on each side to flip through cases. Only one case runs per execution, but all are drawn in the same space.

The selector terminal (a green question mark in a box on the left edge) takes the value that picks a case. Its data type controls the cases:

Selector type Cases
Boolean True and False
Integer 0, 1, 2 ... ranges such as 5..10, and lists such as 1, 3, 7
String Exact text, such as "start", "stop"; comparison is case-sensitive unless you set it
Enum One case per enum item, with item names shown
Error cluster No Error and Error

Right-click the border to Add Case After, Duplicate Case, or Make This the Default Case. A default case is required for integer and string selectors, because the possible values are unlimited. It runs when no other case matches. Be thoughtful about what default does: silently doing nothing can hide bugs, so consider outputting an error there.

Tunnels in cases

Data goes into a Case structure by tunnels, which are visible in every case. Output tunnels need a value in every case. If you forget, the tunnel shows a white (hollow) square and the VI is broken. Right-click the tunnel and choose Use Default If Unwired only when the default (0, False, empty) is truly what you want. Output tunnels are shared by all cases and keep the same type.

Case selectors

Boolean True or False
Integer Values, lists, ranges
String Matching text
Enum Named choices

Integers and strings need a default case.

1 / 2

Choosing the selector type

  • Boolean for yes/no, such as Heater Enabled?.
  • Enum for a fixed set of named choices, the best option for state machines and menus. Enums are checked by the compiler, so a typo in a name is impossible, unlike strings. See state machines later (see the track page).
  • String for text commands, such as those parsed from a serial port. Remember the cases are exact-match.
  • Integer for codes and error numbers.

Use a Type Definition for enums, so edits to the enum list update every case structure that uses it; see clusters and type definitions.

The Select function

For a very small decision, avoid a whole structure: Select (Programming > Comparison) takes a Boolean and two values. If the Boolean is true, it outputs the top value, otherwise the bottom. Both inputs are computed first, which matters when either has a cost or side effect. A Case structure computes only the chosen case.

Other small helpers: Max & Min, In Range and Coerce, and Increment.

Flat Sequence Structure

A Flat Sequence is a film strip of frames that execute left to right. Each frame must finish before the next starts. Data wires pass between frames through sequence locals shown as arrows on the frame borders.

Use it when you need to guarantee order and there is no natural data dependency, for example "open the valve, wait 2 seconds, then read the sensor" where wires don't connect the steps. Prefer wiring the error cluster through the three steps instead when the nodes have error terminals, as that forces order without the structure. The Stacked Sequence (frames stacked on top of each other, shown one at a time) is hard to read and is best avoided in new code.

A Diagram Disable Structure and a Conditional Disable Structure are cousins: they hold alternative diagrams but are decided at edit or compile time, for example to run different code on different targets.

Combining structures

You can nest a Case inside a loop and a loop inside a Case. Keep nesting to two or three levels. Deeper nests are a sign that a subVI is waiting to be extracted; see connector pane and subVIs.

Stand-in 1: a Case structure with a default

This models an integer or string Case structure: a table of cases, with a default. The default returns an error message instead of staying silent.

JS Stand-in: string Case structure with default

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice Start goes to the default because string cases are case-sensitive here.

Stand-in 2: integer ranges and Select

The second stand-in handles integer ranges the way LabVIEW writes them (..), plus a select helper that evaluates both inputs, unlike a case.

JS Stand-in: integer ranges and Select

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Common mistakes

  • Forgetting a default case on a string or integer selector.
  • A hollow output tunnel: one case did not wire its output.
  • Comparing strings with different capitalization.
  • Hiding long logic inside deep stacks of cases.
  • Using a Boolean case where an enum with three or more states is needed.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which selector types require a default case?

    Integers and strings have unlimited possible values, so a default case is required.
  2. 2. What does a hollow output tunnel on a Case structure mean?

    Every case must supply the output or use the default value setting.
  3. 3. How does Select differ from a Case structure?

    Both Select inputs are computed first; a Case runs only one diagram.
  4. 4. In which order do flat sequence frames run?

    Flat sequences run left to right, one frame after the other.

Summary

  • A Case structure runs exactly one case chosen by a Boolean, integer, string, enum or error selector.
  • Integer and string selectors need a default case; every case must supply each output tunnel.
  • Prefer enums over strings for fixed choices.
  • Use Select for tiny decisions and flat sequences (or error wires) when order matters.
  • Keep nesting shallow and move deep logic into subVIs.

Next: Event Structure and Timing