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.
- 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
We can give any reasonable name to an algorithm module.
For algorithm with more than one word name we will use camel-case.
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.
We will use lowercase for variable name.
For more than one word variable we will use camel-case.
Note! Variable name will start with lower-case.
For initializing variable we will use the word Set
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.
Data may be input and assigned to variable using Read statement.
Read: variable list
Read: x, y, z;
Note! Value will be assigned from left to right.
Message and data in variables may be output by using Write or Print statement.
Write: Message and/or variable list
Print: Message and/or variable list
Write: “Hello World”; //message
Print: “Value of x = ”, x; //message and variable
Note! Message and variable is separated by comma , [similar to Python programming]
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.
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.