Pseudo-code, is essentially “fake code”. Well if it’s fake, why should we use it? That is a good question, so let’s look at what it is used for, and isn’t.
Flowcharts are often used to help define the flow of an algorithm. However, they often get long, and hard to manage, especially with larger and larger projects.
Therefore, pseudo-code is sometimes preferred. Now Pseudo-Code isn’t “real” code, (hence the term pseudo), it is an English like set of statements that help us define what the program is supposed to do.
While some people will write full on sentences, most people will just write short fragment blocks. The idea is you don’t have to know a programming language to read or write it. But anyone should be able to pick it up and follow the logic of it and help determine if you made any logical errors.
Some people will indent lines of pseudo-code to show what block they are in, others will use empty lines. In reality, there is no set rule. It’s often based upon how you were taught, and how the company/organization/school you are associated with prefers to have it done.
With Pseudocode, you can replicate all of the features that you would in a flowchart. In fact, it’s easier to show loops in many cases.
Let’s look at some examples. The first one is simple, and converts feet into meters.
get distance in feet
meters = feet x 0.3048
print meters
This pseudo-code is a little more complex. It gets a list of customers. If they own a specific product, they will get an email about an update. Notice that this handles both a loop block of code, and a decision block of code.
get list of all customers
loop through customer list
if current customer has product "X" then
send email alerting customer of free upgrade
end if
end loop through customer list
You may also note the indenting, to make things easier to read, and see what is within a given block of code.
One thing to know about pseudo code is that it might be equal to the lines of computer code, but more than likely, it will actually take a lot more lines of computer code to re-create our logic. That’s OK. Pseudo-code, just like flowcharts, are designed to give us the logic of how to solve the problem so it can be communicated to a developer, whether that is the one creating the pseudo-code, or another developer.
An Introduction to Pseudo-code was originally found on Access 2 Learn