Programming | | Sequential vs. Nested IFTHENELSE pattern: |
Sequential IFTHENELSE pattern: – The sequential IF pattern is used to test
all of the areas, always made one after another. This is done to completely
check every possible answer. The
example program below will test to see if you are 16 and will give you an
output based on one of three tests.
Nested IFTHENELSE pattern: The nested IF pattern is like the sequential
IF pattern, but the logic behind the nested IF is utilized quite
differently. There is no limit on the number of levels of nesting. A nested
pattern is needed when checking the same field for more than two choices or
when checking different fields and the outcome of one decision has a bearing on
the outcome of the other decision. This
same problem (as above) is structured differently so each IF is then nested
within each other. Can you follow the
pattern? When creating a flowchart for
this problem (as show below), you would structure the second and third IF
statements within the false path of the pattern. The code below can be copied. Example Problem 9: This is a simple program that will use the Sequential vs. Nested IFTHENELSE pattern that will allow the IF structure to show you how you can program an IF structure in ether Simple or Nest structure. The two buttons on this for will do will results with the same answer. Please remember to place your name somewhere at the bottom of this form and put a Flowerbox at the top of the code. Save the program as Example 9 and put the form and code together. Please Note: When turning in this Example problem 9 you will need to turn in the Form (during run time) and Code as well as the Program Flowchart for the Sequential and the Nested IFTHENELSE pattern. If structures one right after the other.
Example Problem 9A:
In this example problem you
are inputting a student's name and age, into a form and making a test
based on the student's age. The form design and properties are below.
Flowerbox Template: Put the flower box into the code as shown above.
As you can
see below, there are three IFTHENELSE structures as you must write the code in the Window Application format. As each IF structure has an output statement on the true path notice that there are no steps in the
false path. Again we call this a NULL and the ELSE could be left out of the code. You must understand that with this
structure of design, the program will read every IF line and will only process one of the outputs or true path. You will be asked to write this The Sequential IFTHENELSE in the Sequential button. Once you feel you have done this run the program and make the test it to see if the correct output will displayed. See the code below for example.
The Sequential
IFTHENELSE flowchart: You will asked to write the flowchart for this Sequential
IFTHENELSE structure lead by Mr. Proctor using the classroom board.
Click Here to see the Flowchart
The Sequential Flowchart
If
Val(cmbStudentAge.Text) < 16 Then txtOutput.Text = txtName.Text & ", sorry you’re NOT of age to drive!" End
If txtOutput.Text = txtName.Text & ", you must take a driving test first before you can drive! Best of Luck on the test." End
If txtOutput.Text = txtName.Text & ", you are of age to drive! Be Safe and Drive Safe" End
If
The Nested IFTHENELSE
flowchart: You will asked to write the flowchart for this Nested
IFTHENELSE structure lead by Mr. Proctor using the classroom board.
Click Here to see the Flowchart
The Nested Flowchart
txtOutput.Text = txtName.Text & ", sorry you’re NOT of age to drive!" txtOutput.Text = txtName.Text & ", you must take a driving test first before you can drive! Best of Luck on the test." txtOutput.Text = txtName.Text & ", you are of age to drive! Be Safe and Drive Safe"
Example Problem 9D Can you add another If..Then..Else structure to this program that will test to see if all the data has been entered and if not post a Red color message in the output box that states Missing Data. Note this code below should be support in both the Sequential IF and nest IF buttons.
Flowerbox Template: Put the flower box into the code as shown above.
Also please code the Clear and Exit Button in this program. Once you get the code entered try to run the program to get it working. Keep this simply by using the following Desk Check input below. Please note that you will need to type in a caps A, B, or C for the for the Employees Code. I also ask you to run it and test it many different ways. maybe try entering in a lower case a or b to see the output.
The Desk Check - You will see four different desk check below. Once your program is running try to enter in the inputs to capture the output and screen shots for this example problem.
Teacher Comment: The difference between Sequential IF and Nested IF is quite
simple. In the Sequential IF, all
tests are made in all cases. But, with
the Nested IF, each test is made only if the preceding test is not true.
Directions for turning in Example problem 9 - Virtual:
Virtual No Printing just upload the assignment files to Canvas Module 4 Example Problem 9. You will NOT need to print out any documents just submit this example problem in the Canvas drop box. Note you should have four screen shots: Example 9 Code, and the Form (Run Time screen) and both of the flowcharts Sequential and Nested. Put all screen shots (images) in a Word Document and send me the file. Save the Word document as the example problem: Example 9 and your first and last name. |