Best Practices & Tips for Writing Pseudocode

Instructor: Kent Beckert

Kent is an adjunct faculty member for the College of Business at Embry-Riddle Aeronautical University and has a Master's degree in Technical Management.

Pseudocode is sequentially listed, single lines of English-like statements describing the execution of a software program. We'll discuss program flow methods, provide pseudocode examples for each, and discuss commonly applied best practices.

It is the middle of the week and you still haven't been able to write the source code you need for your latest software program. It seems every time you sit down at your computer to write, you are inundated with questions like: What is the syntax order? Should I use a brace or bracket? Where should the parenthesis go? Thoughts of format, syntax, and special characters crowd your mind and you are unable to focus on the problem at hand. How do I get started? How can I sequence the program when I am so concerned over what source code syntax to use?

Try this. Get up from your computer and go to a semi-secluded spot taking only writing materials with you. The idea is to get away from the computer and plan your coding project instead of trying to write the syntax. Now, on the paper or whiteboard, transcribe your thoughts into sequential English-like statements, not worrying about syntax requirements, commas, brackets etc. What I'm saying is: before you write a single line of C++ or Java programming code, write the algorithm in pseudocode.

What is Pseudocode?

In computer programming, a software program is comprised of sequentially listed instructions designed to provide the desired output. We all have executed a series of instructions, perhaps not in a programming language like Java or C++, but in the form of an algorithm, basically a sequence of steps that when followed results in an output, like following the steps outlined in a cake recipe. Programmers, music writers, bakers, cooks, and many others use algorithms to organize and solve problems. In most instances, these algorithms could be considered pseudocode.

Let's look at a pseudocode example that finds an average of several numbers. Remember, when writing pseudocode you are not concerned with syntax, just statements describing a single action. This is one pseudocode option for finding our average:

  1. Set all variables to zero (total, counter, average)
  2. Request user to input the first number; save inputted number as 'total'
    1. Increment counter by 1 save as counter
    2. Request user to input next number
    3. Add inputted number to total
    4. Continue at step 3 until all numbers are entered and added to total
    5. Divide total by counter
  3. Display results as average

Flow Control Methods

In general, the flow defines the way a program executes and is structured using the flow control method or construct best fitting the intent of the program. Keep things simple and separate your program into individual actions working on one action (statement) at a time. We will tie everything together later.

Flow Control Method Description
Sequential Program code executed in the order listed.
Selection Direction of the program is dictated by choice or comparing a value.
Loop A loop controls the number of times a given call or sub-routine will execute before the loop is exited.
Call Often referred to as sub-routines or method calls, these are often embedded within the main program. If instructed to execute a method call or sub-routine, flow is interrupted to begin processing the designated method or sub-routine call.

Pseudocode Flow Method - Sequence

Let's take a look at how pseudocode could be used in a program about temperatures for each of the flow methods listed in the table above. We'll begin with Sequence. In a sequenced program, instructions are executed one after another in the order listed. Our pseudocode for determining the difference between two Fahrenheit temperatures could be:

  1. Input first temperature
  2. Input the second temperature
  3. Subtract the second temperature from the first temperature
  4. Display the difference

Pseudocode Flow Method - Selection

Sequence doesn't look so bad, right? Let's take a look at our next construct: Selection. Remember, in a Selection construct, the program flow is altered based on a selection or compared value. A possible pseudocode for determining if an entered temperature is freezing or not is as follows:

  1. Input temperature
  2. Check to see if the temperature is equal to or less than 32 degrees
  3. BEGIN IF
    1. If the entered temperature is equal to or less than 32 degrees display: Temperature is freezing
    2. If the entered temperature is not equal to or less than 32 degrees display: Temperature is above freezing
  4. END IF
  5. Continue program flow

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support