Professional Documents
Culture Documents
Pseudocode Presenation
Pseudocode Presenation
ALGORITHM
What is a Pseudocode
Pseudocode is Pseudocode Program Construct
A language similar to a Statements are not executed by the
1. Sequence
programming language but the computer but are used by programmers
as the foundation for developing 2. Selection
rules are not as stringent. Each
statement must have the correct programming codes. 3. Iteration / Repetition/
syntax. It is used as a guide to code the Loop
an imitation of a computer solution to the problem in a high
program written using language.
mathematical notations and Pseudocodes and programs are made
English-like statements to up of four kinds of statements:
describe the logic of solving a Input
problem or carrying out a Processing
procedure. It is used in place of Control
symbols or flowcharts. Output statements.
Allow input for a program
in other words is used to get
STATEMENT computer.
As data is entered into the
computer, it is stored in the
computer’s memory in
variables, or it may be stored
in tables so that it can be
INPUT accessed when needed for
processing.
STATEMENT
Data can also be stored in a
statement in the form of
constants.
The commands that are used
to permit the input of data are
STATEMENT
Syntax : READ Variable name
When more than one variable is
used, place the comma between
each variable.
READ Variable name, variable
INPUT name
STATEMENT
Input Statement
Solutions
Example 1
READ Quantity, Price Write an instruction to
input the quantity and
price of an item.
Example 2
READ Score 1, Score 2, Score 3
Write an instruction to read
three scores
Class Work
Write instructions to input the following:
A number
01
The name, age and height of
02 a student
STATEMENT
The command that is used to
produce the output is PRINT.
OUTPUT
STATEMENT
OUTPUTTING THE VALUE
OF A VARIABLE
NB When a variable is printed, the content of the variable is printed and not the
name of the variable. The computer locates the segment of memory with the
name of the variable and print the information that is stored in that segment.
Output Statement
A = 10
PRINT A Example
The Variable is A, The value
NB: The variable used with the PRINT instruction must
not be a new variable that is being introduced in the is 10.
instruction but should be a variable that was executed in The 2nd instruction causes 10
an instruction before the PRINT instruction. Hence, it is
to be printed and not A
necessary to refer to prior instructions to ensure that this
rule is enforced. because 10 is what is in A.
OUTPUTTING A Message
1. “Today is Monday”
2. Simone Anderson
3. To read and print the name of a student
4. To read and output the license plate number, route
it will be travelling and number of passengers of
a car
A statement that assigns a
value to a variable is called an
assignment statement. It has
two parts:
1. LVALUE
ASSIGNMENT 2. RVALUE
STATEMENT
The LVALUE refers to the
variable as the storage
location where the RVALUE
will be stored.
ASSIGNMENT
STATEMENT
The RVALUE refers to a
value, which may be the result
of an expression or the content
of another variable.
ASSIGNMENT
STATEMENT
Assignment Statement
01 02 03
04 05 06
07
STOP
Class Work Solution
Declare hworKed as Float For this pseudocode, we need
Declare Hrate as Float three (3) variables because we
Declare DaysPay as Float
need to store three (3) pieces of
START
DaysPay = 0 information hours worked, hourly
PRINT “Enter the hours worked and rate and days’ salary.
hourly rate” Therefore:
READ hworKed, Hrate hworKed
DaysPay = hworKed * Hrate
Hrate
PRINT “Day’s Salary is: $”, DaysPay
STOP DaysPay
An instruction containing the
command IF allows deviation
and selection to take place.
Given criteria are used to form
conditions.
SELECTION
CONSTRUCTS
A condition is made up of three parts:
01 02 03
Variable that was carried Relational operator A variable that was carried
out before out before, a constant or
value.
Condition Examples
Conditions may involve data of different
Colour = “blue” data types. When the data of the condition
Style = “straps” is the character data type, the data should
Heel = “4-inch”
be enclosed in quotation marks.
Cost = “$75”
CONSTRUCTS
IF-THEN Construct
This is used when one
option is available, and a
IF W_Condition = “rain is falling” THEN selection may or may not
PRINT “take umbrella” be made.
ENDIF
IF-THEN-ELSE
IF W_Condition = “rain is falling” THEN
PRINT “take an umbrella” This is used when two
ELSE options are available, and a
PRINT “Don’t take an umbrella” selection must be made.
ENDIF
IF-THEN-ELSE-IF
IF Choice= 1 THEN
PRINT “You are ordering Fried This is used when two or
Chicken”
ELSEIF Choice= 2 THEN more options are available,
PRINT “You are ordering Chicken and a selection may or may
Soup”
not be made.
ELSEIF Choice= 3 THEN
PRINT “You are ordering Patty”
ENDIF
ENDIF
ENDIF
Making Selection
Based on Two or The selection to be chosen could depend on
two or more conditions. When this is
More Conditions required, logical operators AND and OR are
used.
Making Selection Based on Two or More Conditions
ITERATION
CONSTRUCTS
Once a loop terminates, control
is returned to the first sentence
after the block of sentences in
the loop.
ITERATION
CONSTRUCTS
Types of Loop
Indefinite Definite
Also known as a "for loop". Executes
Also known as a conditional loop. its body of code as for a fixed number
Executes its body of code as long as a of times. The term "definite" signifies
specified condition remains true. Will that the number of iterations is known
execute until certain conditions are before the loop starts executing.
met. FOR Loop
(WHILE or REPEAT Loops)
While Loop
With the while loop you have
A User Input
B Check Condition
C Perform Statements
Repeatedly executes a
statement or a block of
statements as long as the
condition is true.
WHILE
LOOP
Condition in a while loop is
tested at the beginning of the
loop, so it is possible for the
statement not to be executed at
WHILE all.
LOOP
WHILE Loop General Form
WHILE <CONDITION>
<STATEMENT>
ENDWHILE
OR
A User Input
B Perform statements
C Check Condition
Executes a statement or a
block of statements as long as
the specified condition in the
UNTIL statement is false.
REPEAT- UNTIL
LOOP
Note that this condition is
tested at the end of the loop, so
the statement will always be
executed at least once.
REPEAT- UNTIL
LOOP
REPEAT-UNTIL Loop General Form
REPEAT
<STATEMENT>
UNTIL (CONDITION)
OR
REPEAT
<STATEMENT>
UNTIL <CONDITION IS TRUE>
REPEAT-UNTIL Loop General Form
REPEAT
STATEMENT 1
STATEMENT 2 If you have a block of
STATEMENT 3
statements, then they are
………
UNTIL (CONDITION is True) placed between REPEAT and
UNTIL statements
EXAMPLES
STOP
EXAMPLES
A Variable
B Equal
C Start Value
C To End Value
FOR Loop General Form
Declare A , B, C, i as Integer.
START
A=5
B = 10
FOR i = A TO B DO
C=i+B
PRINT “The value of C is:”, C
ENDFOR
STOP
Class Work
Write a program that will prompt the user to enter a number until the user enters a
greater than 100. Once a number greater than 100 is entered, the program should
print "Number exceeds 100" and stop.
Class Work
Write pseudocode for a program that continues to print "Hello, World!" until a user
enters the word "stop".
Class Work
Write pseudocode for a program that prints out the first ten multiples of a number
provided by the user.
“Problem-solving is the adventure of the
mind. Each challenge, a puzzle; every
solution, a triumph. Dive in, think deeply,
emerge wiser. Your journey shapes the world,
one solution at a time."