Pseudocodes: Structured English For Defining Algorithms
Pseudocodes: Structured English For Defining Algorithms
IF condition THEN
Sequence 1
ELSE
Sequence 2
ENDIF
If a student gets a grade of 60 and
above, then the student passes the
course; otherwise, the student fails.
WHILE
Conditional Loop
Evaluation after each iteration
Condition must be satisfied to end
WHILE condition
SEQUENCE
WHILE Population < Limit
Compute Population as Population +
Births Deaths
Compute for the class
average of ten quiz scores.
CASE
Indicates a multi-way branch based
on mutually exclusive conditions
CASE expression OF
condition 1 : sequence 1
condition 2 : sequence 2
condition n : sequence n
CASE grade OF
A : print points = 4
B : print points = 3
C : print points = 2
D : print points = 1
F : print points = 0
FOR
a specialized construct for iterating a
specific number of times, often called a
"counting" loop
FOR iteration bounds
sequence
FOR grade = 94 to
100Student gets an A
Add 1 to A grade counter
Nested Constructs
Constructs embedded within each
other
Indicated by indentation
If a student gets a grade of 60 and above, the
student passes the course, if the student gets a
grade of 75 or greater, then the student qualifies for
a special course.
If a player rolls a dice and gets 6, he gets
100 pesos. If the value is 5 then he or she
gets another shot; Else, he gets nothing.
Exercises
Subtract 2 numbers. If the result is
positive, say Positive; if the result
is negative, say Negative. If the
result is 0, say Zero
Mark a 10 question test and compute
a grade on a 10-point scale. Convert
the score to a letter grade based on
the following:
A= 90-100 C= 70-79
B= 80-89 F = 69 and below