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

what is defense mechanism
Chinaza Reply
what is defense mechanisms
Chinaza
I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai 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