Introduction to Fortran

Pseudocoding

Though it doesn’t appear so when we use complicated words like “algorithm” to describe sometimes complex processes in computing, we all use algorithms every day.

A simple example would be deciding what to do when approaching a stop light: drive through it, slow down in preparation to stop, or stop fully. Your decision depends upon which color the light is.

Your thought process might go something like this:

  1. If light is green, drive through intersection
  2. If light is yellow, slow down and prepare to stop
  3. If light is red, come to quick stop before intersection

The above is an example of pseudocode - a humanized version of computer code meant to be written in sentence form instead of coded bytes. Pseudo-code has no standards except that it is an attempt at organizing your current thoughts into a form that would resemble the flow/sequence of a computer program.

Pseudocode is made to resemble the tasks you intend to have the computer perform. These tasks need to be in order for the computer to know how to execute some of the commands. For instance, if you would like to do some math with variables, the program would need to know the values of the variables before being able to do the math.

So, the order of pseudocode makes a difference. The specific words you choose to use don’t make a difference as long as the pseudocode makes sense to you. Your pseudocode may not come out in the right order on the first try. That isn’t a problem. You can always move pseudocode around without serious implications. Moving code snippets around after the program is written is more problematic.

Let’s now consider a more complex task: How does a person decide what to wear on any given day?

Every morning, we get up and have to decide what to wear. We make decisions based on if the weather is one way or another using variables like temperature, precipitation forecasts, or predicted cloud cover. We make different clothing decisions based on whether it is the weekend or not. And we make decisions based on the array of clothes we have that are clean. After picking out clothes for the day, we might even consider how that changes the amount of clean clothes remaining, since we have subtracted some clothes from our closet. We might mentally print a reminder: “Do laundry today!”

Each of the bold words in our paragraph hint at important parts of the “what to wear today” algorithm. Let’s now step through making an algorithm, or program, in pseudocode that will pick the appropriate clothing for us based on several inputs.