Nested pattern
Example: If you are checking for several codes. You have a choice of code 1, code 2 or code 3. If you know the code is 1 then there is no reason to check for code 2 or code 3. Therefore, if the result of the decision CODE = 1 is true then the next decisions are not performed. If the result of the decision CODE = 1 is false then the next decisions are performed. If a decision is made on the true path of one decision, the next decision is performed only if the result of the of the first decision is true.
Another Example: If you are checking the income and marital status of a certain person. You want to output all people that earn more than $50,000 and are single. If the decision income > $50,000 is true then you need to check the marital status to see if they are also single.
NOTE: To connect the decisions with a nested solution, start with the last decision listed and connect the true path and false path together. Work your way to the top of the nested structure until all the decisions are connected. The number of connector symbols in the flowchart and the number of decision symbols will match. In pseudocode, the number of IF, THEN and ENDIF statements will match and line up.
In pseudocode: In pseudocode:
3. Problems using the Sequential pattern –
In pseudocode:
4. Difference between the problems solved using Sequential and Nested IF patterns.
Sequential Pseudocode Example:
Pseudocode Example:
Flowchart Example:
Exercises:
Problem #13 – To solve this problem, the students need to think of the number line from math. How do you know if a number is positive or negative? A positive number is greater than zero and a negative number is less than zero. This is a nested problem because there is one field (Number) with more that 2 choices (positive, negative and zero).
Problem # 14 – This problem is nested because there are two fields (height and weight) and the decisions for the height and weight are related.
Problem #15 – This problem is nested because it is checking the field (job code) for more than two choices.
Problems # 16 & 17 – These
problems are excellent problems to use to study for the final exam.