Introduction to Algorithms and Programming
Pseudo code is a simple method to develop and describe a variety of problems. It is especially effective for describing problems intended to be implemented with software.
Rules of thumb when writing pseudo code
- As much as possible, use plain words and language from the problem domain.
- The pseudo code should not be dependent on the C programming language.
- Write one statement per line.
- Each line should describe at most one step, action or task.
- Write important keywords in full uppercase (ALL CAPS).
- It shows your view of the important elements of the solution.
- Consistently indent statements to show relationship hierarchy.
- This is especially applicable for procedural solutions.
- Each complex statement should have a START line and an END line.
- A complex statement is any combination of two or more lines.
SEQUENCE control structure
This is the simplest control structure which is expressed in pseudo code by writing one statement after another
. The statement above always takes place before the statement below.
IF-THEN-ELSE control structure
This control structure describes a choice between two or more alternatives
IF test question
The ELSE block is optional. If it is not present, then, the alternative is no action.
WHILE control structure
This control structure describes the situation in which one or more statements are repeated as long as the answer to a test question is true
WHILE test question
The logic of the test question is very important to the WHILE control structure.
The answer to the test questions must be true or false.