0% found this document useful (0 votes)
15 views

Ch8-Pseudocode

Pseudocode is an informal representation of code that allows users to outline algorithms without adhering to strict syntax. It serves as a bridge between human ideas and programming languages, facilitating communication of concepts. Key structured programming constructs in pseudocode include SEQUENCE, IF-THEN-ELSE, FOR, WHILE, REPEAT-UNTIL, and CASE.

Uploaded by

Roina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Ch8-Pseudocode

Pseudocode is an informal representation of code that allows users to outline algorithms without adhering to strict syntax. It serves as a bridge between human ideas and programming languages, facilitating communication of concepts. Key structured programming constructs in pseudocode include SEQUENCE, IF-THEN-ELSE, FOR, WHILE, REPEAT-UNTIL, and CASE.

Uploaded by

Roina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Pseudocode

An informal way to create a rough draft or program outline.

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?

1. Arrange the sequence of tasks you want to complete.


2. Define a statement that establishes the primary goal.
3. Indent the IF-ELSE, FOR and WHILE loops in the pseudocode.
4. Follow standard naming conventions.
5. Keep in mind the common sentence casings like a lower case for variables, upper
case for constants, and CamelCase for methods.
6. Avoid making the pseudocode abstract.
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.

FOR (<iteration limits>);


<sequence>;
ENDFOR
WHILE
● It specifies a loop which contains a condition at the top.
● WHILE will indicate the beginning of the loop .
● ENDWHILE marks the ending of the loop.
REPEAT-UNTIL
● It shares similarity with the WHILE loop .
● However, the condition test is done at the end of the loop, not at the start.

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

SET total to zero


REPEAT
READ Temperature
IF Temperature > Freezing THEN
INCREMENT total
END IF
UNTIL Temperature < zero
Print total
Final Words
● Pseudocode refers to an informal way to write a program.
● One cannot classify it as a computer program because it represents the program
algorithm in a simplistic and natural language.
● Since you write it in simple English language, there is no strict syntax of writing a
Pseudocode like other programming languages.
● There are six structured programming constructs in pseudocode.

You might also like