Introduction to Fortran

Simple Program Construction with Pseudocode » Nesting

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:

Good Example (fewer lines) Content

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.

Bad Example (more lines) Content

  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

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.