Back

What is pseudocode?

What is Pseudocode?

We use pseudocode in various fields of programming, whether it be app development, data science or web development. Pseudocode is a technique used to describe the distinct steps of an algorithm in a manner that’s easy to understand for anyone with basic programming knowledge. Although pseudocode is a syntax-free description of an algorithm, it must provide a full description of the algorithm’s logic so that moving from pseudocode to implementation is merely a task of translating each line into code using the syntax of any given programming language.

The main constructs of pseudocode

At its core pseudocode is the ability to represent six programming constructs (always written in uppercase): SEQUENCE, CASE, WHILE, REPEAT-UNTIL, FOR, and IF-THEN-ELSE. These constructs — also called keywords —are used to describe the control flow of the algorithm.

1. SEQUENCE represents linear tasks sequentially performed one after the other.
2. WHILE a loop with a condition at its beginning.
3. REPEAT-UNTIL a loop with a condition at the bottom.
4. FOR another way of looping.
5. IF-THEN-ELSE a conditional statement changing the flow of the algorithm.
6. CASE the generalization form of IF-THEN-ELSE.

PSEUDOCODE CONSTRUCTS

SEQUENCE

To Input:
write READ, OBTAIN, GET

To Output:
write PRINT, DISPLAY, SHOW, OUTPUT

FOR

Iteration bounds sequence:
FOR

To close the for statement:
ENDFOR

WHILE

condition sequence:
WHILE
ENDWHILE

REPEAT-UNTIL

REPEAT
sequence
UNTIL condition

IF THEN ELSE

IF condition THEN
sequence 1
ELSE
sequence 2
ENDIF

How to write Pseudocode

When writing pseudocode, everyone has their own style of presenting since humans are reading it and not a computer; pseudocode’s rules are less rigorous than that of a programming language. However, there are some simple rules that help make pseudocode more universally understood.

1. Always capitalize the initial word (often one of the main 7 constructs).
2. Make only one statement per line.
3. Indent to show hierarchy, improve readability, and show nested constructs.
4. Always end multi-line sections using any of the END keywords (ENDIF, ENDWHILE, etc.).
5. Keep your statements programming language independent.
6. Use the naming domain of the problem, not that of the implementation. For instance: “Append the last name to the first name” instead of “name = first+ last.”
7. Keep it simple, concise and readable.

Why use Pseudocode?

- It's easier to read
- It simplifies code construction
- It's a good middle point between flowchart and code
- It's a helpful starting point for documentation
- It allows for quick bug detection

MESSAGE US