<< Chapter < Page Chapter >> Page >
The creation of this content was supported in some part by NSF grant 0538934.

Case structure

The case structure allows data to flow based on a integer, Boolean or string matching condition. The case executed is selected based on the data wired to the Case Selector .

A screen capture of a 'Case Structure' icon. The 'Case Selector' is labeled on the left and the 'Selector Label' is on the right.
Case Structure

Boolean selection

In the Front Panel window, select a Boolean control and an output string.

A case selection user interface screen cap. There is 'Boolean' button and a 'Case' field.
Case Selection User Interface

Arrange the diagram to look as in [link] .

A row of three icons. From left to right the icons are a boolean icon, a box icon with the word 'true' at the top, and the third icon is a case icon.
Case Selection G Diagram

In the True case, add a string constant containing True Case .

A row of three icons. From left to right the icons are a boolean icon, a box icon with the word 'true' at the top and a pink box in the middle containing 'true case', and the third icon is a case icon.
True Case Diagram

To select the False case, click on the selector label down arrow and select False from the pop-up menu. You can also cycle through the cases by clicking the next (right) or previous (left) arrows.

A row of three icons. From left to right the icons are a boolean icon, a box icon with the word 'true' at the top and a pick box containing 'true case'. There is also a menu on top of this second icon with 'false' highlighted in blue and a check mark next to 'true'. The third icon is a case icon.
Selecting False Case

In the False case, add a string constant containing False Case .

A row of three icons. From left to right the icons are a boolean icon, a box icon with the word 'false' at the top and a pick box containing 'false case'. The third icon is a case icon.
False Case Diagram

Wire the string constant in the case structure to the output string terminal.

A row of three icons. From left to right the icons are a boolean icon, a box icon with the word 'false' at the top and a pick box containing 'false case'. A pink line connects the second icon to the third icon which is a case icon.
Wiring Case Structures

Select the True case and wire the string constant to the case structure tunnel . Complete the diagram as shown in [link] .

A row of three icons. From left to right the icons are a boolean icon connect via a green line to a box icon with the word 'true' at the top and a pick box containing 'true case'. A pink line connects the second icon to the third icon which is a case icon.
Completed Case Diagram

It is important to note that all instances in a case structure must be wired to enable data to flow from the case structure .

In the Front Panel window, toggle the Boolean input control and run the program.

A field with a Boolean button and a case field containing 'Flase Case'.
False Selection
A field with a Boolean button and a case field containing 'True Case'.
True Selection

Multicase selection

Select an Integer 32 numeric input and an Integer 32 numeric output and label them Selector and Case respectively.

A form containing the field 'sector' and the field 'case'. Each field contains 0.
Multicase GUI

In the Block Diagram window, create a case structure , select the False case and arrange the terminals as shown in [link] .

There are three icons. From left to right the icon are a 'sector' icon, a box with 'false' on top and the third icon is a 'case' icon.
Multicase

Wire the Selector numeric control to the case selector on the case structure. The selector label reflects the diagram update.

There are three icons. From left to right the icons are a 'sector' icon connected via a blue line to a box with '0, Default' on top and the third icon is a 'case' icon.
Multicase Selector

In the 0, Default case, add a numeric constant and leave its value as 0.

There are three icons. From left to right the icons are a 'sector' icon connected via a blue line to a box with '0, Default' on top and their is a '0' in the middle. This box is connected to the third icon which is a 'case' icon.
Default Case

Using the selector label , select case 1. Add a numeric constant, enter 1 and wire it to the case tunnel. The resulting diagram is shown in [link] .

There are three icons. From left to right the icons are a 'sector' icon connected via a blue line to a box with '1' on top and their is a '1' in the middle. This box is connected to the third icon which is a 'case' icon.
Case 1

Right click anywhere in the case structure and select Add Case After from the pop-up menu.

A row of icons with a menu overlaid. From left to right there is an icon labeled 'sector' connected to a large box via a blue line. The item 'Add Case After' is highlighted in blue on the menu.
Adding Cases

Case 2 is added after case 1. Add a numeric constant, enter 2 and wire it to the case structure tunnel.

There are three icons. From left to right the icons are a 'sector' icon connected via a blue line to a box with '2' on top and their is a '2' in the middle. This box is connected to the third icon which is a 'case' icon.
Case 2

[link] shows the results of running this simple case selection programs for Selector set to 0, 1, 2 and 3 respectively.

There are four forms with the fields 'Sector' and 'Case' on each. Clockwise from top left the values in 'sector' 'case' pairs are '0,0', '1,1', '2,2' and '3,0'.
Multicase Selection Program

For loop

The For Loop structure repeatedly executes the diagram within the structure. The Loop Count specifies the number of times the loop contents must be executed and the Loop Iteration indicates which iteration is currently being executed.

An icon containing a blue square with an 'N' in the top left corner that is labeled 'Loop Count'. Another blue square containing 'i' is near the bottom left of the box and is labeled 'Loop Iteration'.
For Loop Structure

The Loop Count and Loop Iteration are of Integer 32 data types. If the Loop Count is set to N , then the Loop Iteration value range is from 0 to N-1 . This is illustrated in [link] and [link] .

A blue box labeled 'Loop Count' connects to a box with a blue box containing 'N' at the top left and a blue box containing 'i' at the bottom left. The 'i' box is connected within the big box to an icon labeled 'Iteration'.
Loop Count

A form with the field 'loop count' with a value of '100' and the field 'iteration' with a value of '99'.
Final Loop Iteration

Shift registers

Shift Registers allow the preservation of intermediate results between sequences of iterations.

A large box containg a blue box 'N' and a blue box 'i'. A pair of two down arrows are labeled 'shift registers'. An up arrow is opposite the down arrows.
Shift Registers
A large box containg a blue box 'N' and a blue box 'i'. A pair of two down arrows are labeled from top to bottom 'i-1' and 'i-2' and collectively they are labeled 'result at iteration'. An up arrow is opposite the down arrows and is labeled 'i' and 'Result at iteration'.
Shift Registers

To add a Shift Register , right click on the For Loop structure and select Add Shift Register from the pop-up menu.

A large box with an blue box 'N' at the upper left corner and an 'i' in a blue box at the lower left. A menu exists on the right with the item 'Add Shift Register' is highlighted in blue.
Adding Shift Registers

To add elements to the shift register , right click on the shift register and select Add Element from the pop-up menu.

Questions & Answers

Why does water move through a membrane?
Christina Reply
How many bones are in the human skeleton
Treasure Reply
203
Oyeleke
procce of digestion of proteins a long human alimentarycanal
Carson Reply
what are the properties of lipids?
Isiah Reply
They are: Fatty acids, fats, oils, waxes, phospholipid, glycolipids, steroids and some vitamins
Rachel
explain why a fresh water fish excrete ammonia
Leonard Reply
plz answer my question
Leonard
sorry i meant it has a nucleous unlike plant cells lol
Lailah
Ammonia is the end product of protein catabolism and is stored in the body of the fish in high concentrations relative to basal excretion rates. Ammonia, if allowed to accumulate, is toxic and is converted to less toxic compounds or excreted
Rachel
What are eukaryotic cells?
Nwosueke Reply
cell with no nucleous so not a plant cell
Lailah
eukaryotic cells are membrane bound organelles that have a membrane bound nucleus
ojeen
where does the cell get energy for active transport processes?
A'Kaysion Reply
IDK maybe glucose
Lailah
what is synapsis
Adepoju Reply
how many turns are required to make a molecule of sucrose in Calvin cycle
Amina Reply
why Calvin cycle occurs in stroma
Amina
why do humans enhale oxygen and exhale carbondioxide?
Maryam Reply
why do humans enhale oxygen and exhale carbondioxide? For the purpose of breaking down the food
dil
what is allele
uzoka Reply
process of protein synthesis
SANTOSH Reply
what is cell
Zulf Reply
a cell is a smallest basic, structural and functional unit of life that is capable of self replication
Lucas
why does a fresh water fish excrete ammonia
Leonard
plz answer my question
Leonard
Ammonia is a toxic colorless gas and when its inside the fish biological system is converted to a less toxic compound then excreted in the form of urea. However too much ammonia will kill the fish " Ammonia Poisoning " which is a very common disease among fish.
This
what is cytoplasm
uzoka Reply
cytoplasm is fluid of cell.
Deepak
how many major types of Cloning
Saeed Reply
two
amir
two
Zulf
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Introduction to g programming. OpenStax CNX. Mar 15, 2010 Download for free at http://cnx.org/content/col11192/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Introduction to g programming' conversation and receive update notifications?

Ask