Introduction

Pseudo Code

Next →

About Pseudo code

  • A pseudo code is an informal was to describe a program
  • Pseudo code is not a computer program
  • Pseudo code can use natural language or compact mathematical notation
  • It is a rough sketch of the actual program

Syntax of Pseudo code

  • No standard for pseudo code syntax exists
  • So we don’t have to follow any strict syntax like computer programming language
  • Pseudo code vary in style from author to author
  • Pseudo code commonly borrows its syntax from popular programming languages like C, Fortran, Pascal, Java etc.

Module

  • We write algorithms to solve problems
  • Algorithms are broken down into modules
  • Some problems are simple so they have simple algorithms and few modules
  • Some problems are complex so they have complex algorithms which have more modules

Notation

Name

We can give any reasonable name to an algorithm module.
Example

Sum()

For algorithm with more than one word name we will use camel-case.
Example
FindHighScore()

Note! First letter of every word is in upper-case.
Camel-case is also used in which each word starts with a capital letter except the first word.
Example
findTime()

Variable name

We will use lowercase for variable name.
Example


name
age

For more than one word variable we will use camel-case.
Example

highScore
isGameOver

Note! Variable name will start with lower-case.

Initializing variable

For initializing variable we will use the word Set
Example

Set score = 0;

Initializing several variables
Set x = 0, y = 0, score = 0, isGameOver = false;

Note! Above statement will be executed from left to right.

Input

Data may be input and assigned to variable using Read statement.

Read: variable list

Example
Read: x;
Or
Read: x, y, z;

Note! Value will be assigned from left to right.

Output

Message and data in variables may be output by using Write or Print statement.

Write: Message and/or variable list
or
Print:  Message and/or variable list

Example

Write: “Hello World”;	//message
Print: “Value of x = ”, x;	//message and variable
Note! Message and variable is separated by comma , [similar to Python programming]
We can also use the + sign to join message and variable [similar to JavaScript]

Begin and End

Algorithm will start with a Begin statement and will end with an End statement.

Completion of Algorithm

Algorithm is completed with the execution of the last instruction.
However, we can terminate the execution at any stage using Exit instruction.

Sub Algorithm

We generally divide complex problem into small manageable sub problems and then we develop algorithm for each of the sub problems, called sub algorithm.

About Sub Algorithm

  • Sub algorithm is also referred as module
  • Sub algorithm can not run on its own
  • We need to call it either from main algorithm or from another sub algorithm
  • Sub algorithm is given a name
  • It can also have parameter list
  • It can return value using return statement

Calling an Algorithm Module

We will use the Call statement to call any algorithm module from another module.

Next →