You are on page 1of 28

 

It is a programming analysis tool, that is commonly used for planning the program logic. Pseudo code is made up of two words: pseudo and code . Pseudo means initiation , and code means the set of statements or instructions written in a programming language. Pseudo code act as the outline of a program. It is not the actual programming Language code. It is also called as Program Design Language. Pseudocode is not written using specific syntax of a programming language rather it is written with a combination of generic syntax and normal English language.

Pseudo code uses some keywords to denote programming processes… 1) For getting Input ◦ READ : Input from a file ◦ GET : Input from keyboard 2) For displaying output ◦ PRINT : send output to printer ◦ WRITE : send output to file ◦ PUT, OUTPUT, DISPLAY : send to screen 3) For assigning value to a variable ◦ INITIALIZE, SET: giving initial value to a variable ◦ To assign a value as a result of some processing, the symbols ‘=‘ or ‘’ are written ◦ To keep a variable for later use, the verbs SAVE or STORE are used

4) For performing arithmetic operations + for Add - for Subtract * for Multiply / for Divide ( ) for Parentheses 5) For the Comparison of two variables and the selection of one or two alternate actions as the result of the comparison: IF, THEN, and ELSE 6) When there is a sequence of processing steps that need to be repeated (loop statements), keywords, WHILE or DO WHILE are used in pseudo code

To calculate the total mark and average of each student in a class

READ name,class,m1,m2,m3 Total = m1+m2+m3 Average = Total/3 IF Average is greater than 60 Class obtained= First Class ENDIF WRITE name,Total,Average,Class Obtained

Write one statement per line
Each statement in a pseudo code represents a single action and is written on a separate line.

Capitalize Initial Keywords
The keywords in the pseudo code should be written in all capital letters. Ex: READ, WRITE, IF ,ENDIF


Indent to show hierarchy
Indentation is the process of showing the ‘boundaries’ of the structure. In the loop or selection structure, we must indicate the statement which is fall in the loop or selection by using indentation

Ex: To find the biggest of the given two numbers
READ a, b IF a>b PRINT a is greater ELSE PRINT b is greater ENDIF Stop

Here we have used indentation to show which statements are within the IF structure.


End multiline structure
The indentation is used to indicate what statements are executed within the structure Such structures must be ended and it provides increased clarity. Ex : ENDIF for IF statement


Keep statements language independent
Pseudocode can be written using some of the structures or keywords of any programming language. But it can’t fully depend on any particular language.

 

  


It can be done easily in any word processor The pseudo code instructions are easier to modify in comparison to a flowchart. It can be written easily No special symbols are used. No specific syntax is used. It can be read and understood easily. Converting pseudo code to high level language is very easy as compared with converting a flowchart to high level language. Writing the pseudo code involves much less time compared to drawing an equivalent flowchart.

 

It can be quite lengthy for complex problems There is no standard format for developing a pseudo code. So one pseudo code may be different from another. Pseudocode does not use any kind of pictorial representations for program elements. So as compared to flowchart it is difficult to understand the program logic. For a beginner, it is more difficult to follow the logic or write pseudo code as compared to flowchart.

A program can be developed by using the following three structures    Sequence control structure Selection control structure (Decision Structure) Iteration control structure (looping)

The sequence logic is used for performing instructions one after another. Here the instructions are written in an order in which they are to be performed. The logic flow of sequence structure is from top to bottom.

General representation of Sequence Control Structure in Pseudo code and flowchart

Pseudocode Process 1 Process 2

Flow chart

Process 1
Process n

Process 2

Process n

Example: Multiplication of two numbers

Flowchart
START
Read a , b C=axb Print c STOP

  

It is also called Decision structure It is used for making decisions. It allows the program to make a choice from alternative paths. Mainly three constructs are used in Selection Control Structure  IF …THEN  IF …THEN… ELSE  CASE structure

The IF …THEN Structure specifies that , if the condition is true, then it carries out the process and if it is false, then it skip over the process.

General representation of IF …THEN Structure in Pseudo code and flowchart
Pseudocode IF condition THEN process 1 Flowchart

YES

If condition

END IF

Process 1

NO

Start Read a
yes

If a>0
no

Print a is Positive

Stop

The IF …THEN …ELSE Structure specifies that , if the condition is true, then it executes process 1, else i.e., if the condition is false, then it executes process 2. General representation of IF …THEN …ELSE Structure in Pseudo code and flowchart

Pseudocode IF condition THEN process 1 . . ELSE process 2 . . END IF . .

Flowchart
YES If condition NO

Process 1

Process 2

Start Read a,b
yes

If a>b
no Print b is Greater

Print a is Greater

Stop

The CASE structure is a multiway selection logic structure. In the IF …THEN structure and IF …THEN… ELSE structure , we can check maximum of two conditions. But the CASE structure is used to choose one option from two or more options in the program logic. It specifies that if the value of Type is equal to Type-1, then it executes Process-1, if it is equal to Type-2, then it executes Process-2, if it is equal to Type-3, then it executes Process-3 and so on. END CASE is used to indicate the end of the CASE structure

Flow chart Pseudocode . . CASE Type Case Type-1 : Process -1 Case Type-2 : . . Case Type-n : Process- n . . END CASE Process -2

Type 1
no

yes

Process 1

Type 2
no

yes

Process 2

Type 3
no

yes

Process 3

Example: To Find the Class Obtained by a student by taking student marks as input

start
Read m1,m2,m3

Avg=(m1+m2+m3)/3
If Avg>=60 yes

Print First Class Second Class
Print

No

If Avg>=50 If Avg>=35

yes

No

yes

Third Class

Print

No

Fail

stop

 

This is also called Looping structure. This structure is used for producing loops in programs. Loops are used to execute some instructions , several times based on some condition. The looping continues until the condition is true. Mainly two structures are used in Looping.

 WHILE loop  DO…WHILE loop

In WHILE loop the condition for looping is checked at the beginning of the loop If the condition is false, then the loop will not be executed, otherwise the loop is executed. It is top tested loop.

Pseudocode . WHILE condition . . Body of the loop . . END WHILE
.

Flow chart

condition
yes Body of The loop

no

Start Num=0
while no

Num<5
yes

Num=Num+1

Print Num

stop

In DO…WHILE loop, the condition for the loop is checked at the bottom. Hence the body of the loop is executed atleast once irrespective of the condition. It is the bottom tested loop.

Pseudocode
DO . . Body of the loop . . WHILE condition
.

Flow chart

Body of The loop yes

condition
no

. END DO WHILE

Start Num=0

Num=Num+1

yes

while Num<5 no Print Num

stop