Learning to Program – Pseudocode (Stage 3) an overview

This entry is part 9 of 22 in the series Learning to Program

The next stage in writing a good program is to put the flow into pseudocode.  There are quite a few variations on the types of pseudocode that you may run into.  Some will be generic (like I will be showing) and others will be language-specific.  None are better than the others.  They are just more appropriate for certain applications.

I created a cheat sheet for some students that I tutored this fall.  I will post it here in it’s entirety along with some additions and corrections.

1. If you’ve created a flowchart, then half of your battle is won. While you may have to remember what statement goes with each shape in the flowchart, the rest is already in front of you.

2. Every beginning has an ending. The words that make up the beginnings are:

i) Start

ii) For

iii) While

iv) If

v) Do

vi) Case

vii) { (This is used in programming languages—not so much in Pseudocode)


3. The words that make up the endings are:

i) Stop

ii) EndFor

iii) EndWhile

iv) EndIf

v) Until

vi) EndCase

vii) } (This is the ending point in some programming languages which goes with the {).


4. Everything should be indented 3 or 4 spaces from the previous vertical level, and everything needs to be lined up vertically in the level. For example, “Start” is the first level, so everything else needs to be indented 3 or 4 from that and lined up vertically. If you put another “beginning” statement inside, then everything between it and the ending statement needs to be lined up 3 or 4 spaces in from it, and vertically aligned.

5. You should declare your variables before you use them. At the top of the pseudocode or flowchart. You will want to declare them at the top of the program or method also.

6. Every variable needs a type declared. “num” for numbers, “string” for words or phrases (or groups of numbers with symbols in them), “char” for single characters, single numbers that are not used for calculations or anything else, or symbols, and “Boolean” for True/False answers.

7. Variables are to be written in “camel case” like this: variableName for variables that can be modified, and ALL_CAPS for constants (variables which cannot be modified after they are declared). And most importantly, they need to be written the exact same way throughout the program.

8. If your program involves numbers (such as a “for index = 1 to 10” or “case 1:”) the numbers are listed as numbers, and not written out as words.

9. Values are assigned to the variables during the declaration phase (initializing) and the actual program phase. The value can be a number, string, character, true/false, or even another variable. It must match the type of variable though (cannot assign a string to a num variable, for example).

10. When assigning a value to a variable, the variable should be on the left side of the =. Assigning a value is the same thing as storing the value in the location that is named by the variable (like storing a paper inside of a file folder).

11. If you’re incrementing a variable, this means that you are taking the original value that is stored in the variable, adding another value to it, and then storing the answer back in the variable. It’s typically written like this: variable = variable + value or variable += value (in programming languages).

12. Above all things, variables and constants and method names should be meaningful. You should be able to take pseudocode that you write today, and code it into a programming language at any point in the future. And you should understand what it does at any point in the future.

13. “eof” or other sentinel values are used to signify the end of processing or end of a data file. While you may put “while not eof” in your pseudocode, in the actual program you will see something like “while variableName != “value”” (for example, while studentName != “xxxx”).

14. Methods are modules. Methods are reusable procedures or classes. Classes are able to be used in more than one program, while “methods” are individual to each program.

15. One of the first things that you want to do is create an IPO chart. Figure out what the inputs are, what processing will take place (if any) and what the outputs are. If something is the same (an input and an output) you only need to worry about it once. From the lists, you will create your variables.

16. Phrases like “prompt the user” or “accepts” or “gets from the user” mean that you will use an input statement. If that is the case, you must have an associated print statement before it, so the user knows what you expect them to give you.

17. Phrases like “continuously accepts” or “reads” or “gets from a data file” mean that you will use a get statement. You list everything that you are getting on one line, and don’t need a print statement before it.

18. Initialize your variables. GIGO is a valid thing. GIGO means “Garbage In Garbage Out.” In other words, if you don’t know what you’re starting with, you can’t know what you’re going to end up with. Initializing your variables ensures that you know what you’re starting with.

19. Remember LIFO (Last In First Out). If you use nested statements, the last one you create, should be the first one you end.

20. Your basis for handling data should be this: Get the first piece of data. Deal with that piece of data. Then get another piece. If you’re using a sentinel value, you need to get a new piece in order to check to see if the sentinel value is triggered or not.

21. Finally remember that no matter how unstructured the program looks, if every chunk has one entry and one exit, then it is structured. And it’s what you are shooting for.

22. Cohesion and coupling are part of this. Cohesion and coupling mean that every piece does one thing, and the main piece coordinates everything. You wouldn’t have someone who’s great at painting and horrible at hammering do the hammering, while someone else does the painting. This same theory applies with your methods and programs.

Series Navigation<< Learning to Program – Structure and Spaghetti CodeLearning to Program – Stage 3 Pseudocode commands and reserved words >>

Leave a comment

Your email address will not be published. Required fields are marked *