What is Pseudocode?

Pseudocode is an informal high-level representation of the actual code that shows how an algorithm or a computer program works in plain English.

svg viewer

Why pseudocode?

Writing pseudocode allows you to get those brilliant ideas in your head in front of you without having to worry about the syntax of the programming language. Since it has no specific syntax, it is easy to read and write, and programmers can comfortably communicate ideas and concepts, even if they are working on different programming languages.

svg viewer

Example

Say you want to write a program that prints odd numbers from 00 to 99.

Let’s start by writing it in simple pseudocode.

Remember, this code won’t compile and execute on its own.

set i to 0  
for each i from 0 to 9  
    if i is odd  
        print i  
end for loop

Note: Pseudocode does not have a specific syntax. Your pseudocode can look different from ours.

Pseudocoding may sound trivial to you, and you may want to jump right into coding, but it does make things a lot easier. Now, all you need to do is convert this plain English into actual code.

Here is the above pseudocode translated into C++, Python, and Java code:

#include <iostream>
using namespace std;
int main() {
// Printing odd numbers from 0 to 9
for (int i = 0; i <= 9; i++) {
if (i % 2)
cout << i << endl;
}
}

We recommend writing pseudocode before writing actual code as algorithms and programs can get tricky.
Copyright ©2024 Educative, Inc. All rights reserved