<< 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

A golfer on a fairway is 70 m away from the green, which sits below the level of the fairway by 20 m. If the golfer hits the ball at an angle of 40° with an initial speed of 20 m/s, how close to the green does she come?
Aislinn Reply
cm
tijani
what is titration
John Reply
what is physics
Siyaka Reply
A mouse of mass 200 g falls 100 m down a vertical mine shaft and lands at the bottom with a speed of 8.0 m/s. During its fall, how much work is done on the mouse by air resistance
Jude Reply
Can you compute that for me. Ty
Jude
what is the dimension formula of energy?
David Reply
what is viscosity?
David
what is inorganic
emma Reply
what is chemistry
Youesf Reply
what is inorganic
emma
Chemistry is a branch of science that deals with the study of matter,it composition,it structure and the changes it undergoes
Adjei
please, I'm a physics student and I need help in physics
Adjanou
chemistry could also be understood like the sexual attraction/repulsion of the male and female elements. the reaction varies depending on the energy differences of each given gender. + masculine -female.
Pedro
A ball is thrown straight up.it passes a 2.0m high window 7.50 m off the ground on it path up and takes 1.30 s to go past the window.what was the ball initial velocity
Krampah Reply
2. A sled plus passenger with total mass 50 kg is pulled 20 m across the snow (0.20) at constant velocity by a force directed 25° above the horizontal. Calculate (a) the work of the applied force, (b) the work of friction, and (c) the total work.
Sahid Reply
you have been hired as an espert witness in a court case involving an automobile accident. the accident involved car A of mass 1500kg which crashed into stationary car B of mass 1100kg. the driver of car A applied his brakes 15 m before he skidded and crashed into car B. after the collision, car A s
Samuel Reply
can someone explain to me, an ignorant high school student, why the trend of the graph doesn't follow the fact that the higher frequency a sound wave is, the more power it is, hence, making me think the phons output would follow this general trend?
Joseph Reply
Nevermind i just realied that the graph is the phons output for a person with normal hearing and not just the phons output of the sound waves power, I should read the entire thing next time
Joseph
Follow up question, does anyone know where I can find a graph that accuretly depicts the actual relative "power" output of sound over its frequency instead of just humans hearing
Joseph
"Generation of electrical energy from sound energy | IEEE Conference Publication | IEEE Xplore" ***ieeexplore.ieee.org/document/7150687?reload=true
Ryan
what's motion
Maurice Reply
what are the types of wave
Maurice
answer
Magreth
progressive wave
Magreth
hello friend how are you
Muhammad Reply
fine, how about you?
Mohammed
hi
Mujahid
A string is 3.00 m long with a mass of 5.00 g. The string is held taut with a tension of 500.00 N applied to the string. A pulse is sent down the string. How long does it take the pulse to travel the 3.00 m of the string?
yasuo Reply
Who can show me the full solution in this problem?
Reofrir Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




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