DEV Community

Cover image for Pseudocode Tutorial
cloudytech147
cloudytech147

Posted on

Pseudocode Tutorial

Pseudocode is a mix of technical terms and common English that facilitates computer programmers to write computer algorithms. Before diving into how to write pseudocode, let’s first discuss what pseudocode is and why do we need it.

What is Pseudocode?

pseudocode is the plain English representation of a computer program or algorithm, which specifies the flow and operation of the program.

It is generally used to represent the structural flow of a program, and it is not associated with any specific programming language. The same quality makes it a perfect tool to represent algorithms for various problems.

Some significant points you need to know about pseudocode are:

  • It is not a programming language.
  • It is just a learning and reasoning tool, which is used by programmers and developers to underline how to write the actual code.
  • Pseudocode can not be executed or compiled by any compiler, interpreter, or assembler.
  • Unlike programming language code, pseudocode does not follow a strict structure and syntax. Here, the programmer can write the code syntax as he pleases.

Example

Code to check if the user entered number is odd or even:

C++

This blog also covers how to write pseudocode for c++:-

int main()
{ 
int num;
cout<<"Enter a number";
cin>>num;

if(num%2==0)
    cout<<"Even Number";

else
    cout<<"Odd Number";
}
Enter fullscreen mode Exit fullscreen mode

Pseudocode

num :INPUT “Enter a number”
IF num MOD 2 ===0
    print “Even Number”
ELSE
    print “Odd Number”
Enter fullscreen mode Exit fullscreen mode

How to Write Pseudocode?

As pseudocode does not follow a strict systematic or standard way of being written, so don’t think of writing pseudocode as a strict rule. However, there are some standard conventions that every programmer follows while writing one. These are:

Use capital words for reserved commands or keywords, for example, if you are writing IF…ELSE statements then make sure IF and ELSE be in capital letters.
Write only one statement per line.
Use indentation for the block body. It keeps the body of every component isolated and indenting different pieces of each block will indicate that those pieces of pseudocode go under a less intended section.
Be specific while writing a statement, use plain English to provide a particular description.

Pseudocode for Different Statements

Operators:

  1. Assignment Operator:
=, <- or :=
Enter fullscreen mode Exit fullscreen mode
  1. Comparison Operator:
== , !=, <, >, <= , and >=
Enter fullscreen mode Exit fullscreen mode
  1. Arithmetic Operator:
+,-, *, /, MOD(%)
Enter fullscreen mode Exit fullscreen mode
  1. Logical Operator:
AND, NOT and OR
Enter fullscreen mode Exit fullscreen mode
  1. Sum, Product:
Σ Π
Enter fullscreen mode Exit fullscreen mode

Conclusion

There are no such strict rules to write pseudocode, and thus, the programmer can write it as she wishes, but it should be written in such a manner so that other developers could comprehend the algorithm.

All the examples and syntax we have mentioned here are conventional, and generally, most of the programmer follows the same syntax. If you want, you can modify the code as per to your liking.

In the above example, you can notice that for each component end, we use the END word. But if you want, you can replace it with { } curly braces.

Top comments (0)