Introduction to Fortran

Simple Program Construction with Pseudocode » Looping

We have a really robust outfit selector going. We could look through the entire clean wardrobe now to see if we have used all of one type of clothing. This looking through your wardrobe is called “looping”. You would have to go through your wardrobe to count how many of each type of clothing is left. The process of counting is exactly the same every time. Count the number of clean pieces of clothes in each clothing type. But this needs to be repeated until you are out of clean clothing to count.

An analog clock is a great example of a similar looping event. The only thing your clock’s second-hand does is rotate to the next tooth of the gear every second. Pseudocode for that might look like this:

  1. For every second, do the following:  	a. Rotate second hand by 6°.  		

What could we do to our pseudocode to make it loop through the clean wardrobe appropriately?

  1. Use app to gather forecast high temperature for today.  2. Use calendar to find whether it is a workday or weekend.  3. Catalog your entire wardrobe into short-sleeved, long-sleeved dress, t-shirt,
and long-sleeved tops, and shorts, pants, athletic shorts, and pajama pants. 4. 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 (today is a workday) 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. 5. Subtract today’s outfit from your clean wardrobe. 6. Look through clean clothes a. If no more clean clothes left i. Print out an alert to do laundry.

The indentation here is to help you see where the nesting occurs. The looping structure goes around the entire program.

That is all we have to do in our (simple) program. By writing your pseudocode out, you can easily then write this program in any algorithmic programming language.