A topic that is not completely obvious in pseudocoding is something we call nesting. Nesting some of our statements inside of one another is really useful especially for decision-making processes that are independent but related. In this case, making a clothing decision is based on the temperature outside, but it also matters whether it is a weekend or not because on the weekend you don’t need to dress as nicely. So you would be able to nest these decisions inside of each other like so:
In this example, the sub-bullets would be considered “nested” pseudocode as they would run inside of the “parent” pseudocode. The sub-bullets would typically be indented for readability.
1. If today is a weekend a. If the forecast temperature is at or above 70°F, select a t-shirt,
else select a long-sleeved top. b. If the forecast temperature is above 60°F, select athletic shorts,
else select pajama pants. else a. If the forecast temperature is at or above 70°F, select a short-sleeved top,
else select a long-sleeved dress top. b. If the forecast temperature is above 60°F, select shorts,
else select pants.
This pseudocode would work well as it has fewer decision points that need to be evaluated to get to the final step. From a coding perspective, the fewer decisions it takes to get to the end goal, the better and more efficient the code.
1. If the forecast temperature is at or above 70°F a. If today is a weekend, select a t-shirt,
else select a short-sleeved top Else a. If today is a weekend, select a long-sleeved top,
else select a long-sleeved dress top 2. If the forecast temperature is above 60°F, a. If today is a weekend, select athletic shorts,
else select shorts Else a. If today is a weekend, select pajama pants,
else select pants
This pseudocode would work, but not as well as if it had fewer parent-level decision points to get to the final step. From a coding perspective, the fewer parent-level decisions it takes to get to the end goal, the better and more efficient the code. In this scenario, we have 4 parent-level decisions, while in the previous version we have only 2.
The fewer decision points we have to go through to get the “answer” the better in any sort of decision tree when evaluating for computing efficiency.