Ch8-Pseudocode
Ch8-Pseudocode
Chapter: 8
Pseudocode
● Pseudocode is an informal representation of the actual code.
● There is no pre-defined syntax for pseudocode.
● Pseudocode helps users pen down brilliant ideas without worrying about the syntax.
● One can comfortably communicate the ideas and concepts with a Pseudocode, while
working on different programming languages.
A Simple Representation of Flowchart
in Pseudocode
Difference – Algorithm and Pseudocode
● While pseudocode is a way to write an algorithm, an algorithm defines the step-by-
step procedure for solving a problem.
● One cannot classify pseudocode as a computer program because it represents the
program algorithm in a simplistic and natural language.
● An algorithm consists of a fixed set of instructions, where each instruction gets
executed in a finite amount of time.
Difference – Algorithm and Pseudocode
Algorithm Pseudocode
1. Get the number of hours 1.1 Display “Enter number of
worked. hours”
2. Get the hourly pay rate. 1.2 Input Hours
3. Multiply the number of hours 2.1 Display “Enter hourly pay
worked by hourly pay rate. rate”
4. Display the result of the 2.2 Input payrate
calculation performed in step 3. Set grossPay=hours*payRate
3. 4. Display “The gross pay is”,
grossPay
How To Write Pseudocode?
7. Use ‘IF-THEN,’ ‘WHILE,’ ‘CASES,’ ‘FOR' the way you would use them in
programming.
8. DO NOT incorporate too much technical jargon in a pseudocode.
9. Recheck all the sections to see if they are complete and clear to understand, after you
have finished writing the pseudocode.
Branches, Conditions, And Decisions
Using Pseudocode
● There are six structured programming constructs in pseudocode. These are
1. SEQUENCE
2. IF-THEN-ELSE
3. FOR
4. WHILE
5. REPEAT-UNTIL
6. CASE.
SEQUENCE
● Indicate sequential control by writing an action after the other .
● Each step is in-line with itself.
● Every step is aligned with the same indent.
● The order of performing the actions in the sequence (top to bottom) in which they are
written.
SEQUENCE
IF-THEN-ELSE
● It is used to display a binary choice for a Boolean condition.
FOR
● This loop is a specialized construct .
● It is used for iterating a specific number of times, often called a "counting" loop.
REPEAT;
<sequence>;
UNTIL (<condition>)
CASE
● It represents a multiway branch based on mutually exclusive conditions.
CASE <expression> OF
(<condition 1>) series 1;
(< condition 2>) series 2;
... (<condition n>) series n;
ENDCASE
NESTED CONSTRUCTS
● They are used to embed constructs within each other by using indenting in a
pseudocode.
● You must indent the nested constructs from the surrounding constructs.
Example of a NESTED CONSTRUCT