Learning outcome c) COUNTER-CONTROLLED REPETITION – WITH n NUMBER OF TIMES Terms
2.1 Design a Solution (Pseudocode)
Definition : Used to tell a
(d) Apply appropriate control structures. Initialization – Initial value of the accumulator program to execute
(Repetition: counter-controlled, sentinel- →set sum/total = 0 statements repeatedly.
controlled) in computational problem solving.
(before condition) A counter variable is any
numeric variable used to
LY2020001226 RULES : Input –Input / Read value of n count the number of
times a loop has occurred
Four elements →Read n WATCH ME! that can be counted by
that are required (before condition) incrementing or
decrementing its value.
a) INTRODUCTION TO REPETITION WATCH ME! to perform
counter- An accumulator is the
variable used to keep the
Two types of repetition controlled total of a series of
numbers or An
Counter-controlled Repetition Sentinel-controlled Repetition repetition with n Condition – Test the loop control variable accumulator is a numeric
of times whether the loop should continue or stop variable used to total or
accumulate values.
A counter-controlled loop repeats a A sentinel-controlled loop uses a (IICU)
specific number of times - User sentinel value to stop a loop - User Infinite loop : a loop that
knows exactly or user can enter how uses special input value to signifies Update Counter – Could be increment or never stops executing.
many times the loop body need to be the end of the input decrement where the value of the loop control
executed variable is updated (before endwhile) Quick Access
b) COUNTER-CONTROLLED REPETITION d) COUNTER-CONTROLLED REPETITION - ACCUMULATE
Initialization – Initial value
Initialization – of the accumulator
Initializes the loop’s
control variable →set sum/total = 0
(before condition) (before condition) WATCH ME!
RULES : WATCH ME! RULES : Formula – Update
Three elements Three elements the value that is
that are required to that are required
Condition – Test held by
perform counter- the loop control to perform
controlled variable whether accumulation accumulator
repetition the loop should
continue or stop Quick Access (IFP) → sum = sum + ___ Quick
(ICU) Access
Update Counter – Could (before update
be increment or counter)
decrement where the
value of the loop control *Print– Print the value that
variable is updated is held by accumulator OR
(before endwhile) calculate the formula of
average
→ print sum
(after endwhile)
Learning outcome (SDS) Terms
2.1 Design a Solution (Pseudocode)
(d) Apply appropriate control structures. Definition : Used to
(Repetition: counter-controlled, sentinel-controlled) in computational problem solving. tell a program to
execute statements
a) INTRODUCTION TO REPETITION repeatedly.
Two types of repetition A counter variable is
any numeric
Counter-controlled Repetition Sentinel-controlled Repetition variable used to
count the number
A counter-controlled loop repeats a specific A sentinel-controlled loop uses a sentinel of times a loop has
number of times - User knows exactly or user value to stop a loop - User uses special input occurred that can be
can enter how many times the loop body need value to signifies the end of the input counted by
to be executed incrementing or
decrementing its
Quick Access value.
WATCH ME! An accumulator is
the variable used to
LY2020001226 keep the total of a
series of numbers or
An accumulator is a
numeric variable
used to total or
accumulate values.
Infinite loop : a loop
that never stops
executing.
Learning outcome (SDS)
2.1 Design a Solution (Pseudocode)
(d) Apply appropriate control structures.
(Repetition: counter-controlled, sentinel-controlled) in computational problem solving.
b) COUNTER-CONTROLLED REPETITION WATCH ME!
RULES : Initialization – Initializes the loop’s
control variable
Three elements that (before condition)
are required to
perform counter- Condition – Test the loop control
variable whether the loop should
controlled repetition continue or stop
(ICU) Update Counter – Could be increment
or decrement where the value of the
loop control variable is updated
(before endwhile)
LY2020001226
Learning outcome (SDS)
2.1 Design a Solution (Pseudocode)
(d) Apply appropriate control structures.
(Repetition: counter-controlled, sentinel-controlled) in computational problem solving.
c) COUNTER-CONTROLLED REPETITION – WITH n NUMBER OF TIMES
Initialization – Initial value of the
accumulator
→set sum/total = 0
(before condition)
RULES : Input –Input / Read value of n
→Read n
Four elements that (before condition)
are required to
perform counter- Condition – Test the loop control
controlled variable whether the loop should
continue or stop
repetition with n of
times Update Counter – Could be increment or
decrement where the value of the loop
(IICU) control variable is updated (before endwhile)
WATCH ME!
LY2020001226
Learning outcome (SDS)
2.1 Design a Solution (Pseudocode)
(d) Apply appropriate control structures.
(Repetition: counter-controlled, sentinel-controlled) in computational problem solving.
d) COUNTER-CONTROLLED REPETITION - ACCUMULATE WATCH ME!
Initialization – Initial value of the
accumulator
→set sum/total = 0
(before condition)
RULES : Formula – Update the value that Quick Access
is held by accumulator
Three elements that → sum = sum + ___ LY2020001226
are required to (before update counter)
perform accumulation *Print– Print the value that is held by
accumulator OR calculate the formula of
(IFP) average
→ print sum
(after endwhile)
e) COUNTER-CONTROLLED REPETITION (FREQUENCY) WATCH ME! g) SENTINEL-CONTROLLED REPETITION (MAXIMUM) WATCH ME!
RULES : Initialization – RULES : Initialization – Initial value of
Initial value of the the maximum (set as lowest
Three elements frequency Three elements value)
that are required →set freq = 0 that are required →set max = 0 / -99999
(before condition)
to perform (before condition) to perform
frequency maximum Formula - compare the variable
Formula – Update with initial value of maximum
(IFP) the value of (IFP) → if ( variable > max)
frequency that is
held by freq max = variable
→ freq = freq + 1 endif
(before update input)
(before update
counter) *Print– Print the value that is
held by maximum
*Print– Print the → print max
value that is held by (after endwhile)
freq
→ print freq
(after endwhile)
f) SENTINEL-CONTROLLED REPETITION WATCH ME! h) SENTINEL-CONTROLLED REPETITION (MINIMUM) WATCH ME! Quick Access
RULES : Prime Input – RULES : Initialization – Initial value of the
Initializes the loop’s minimum (set as highest value)
Three elements control variable Three elements →set min = 100 / 99999
that are required to that are required (before condition)
Condition – Test
perform counter- the loop control to perform Formula – compare the variable with
controlled variable whether minimum initial value of minimum
repetition the loop should → if ( variable > min)
continue or stop (IFP)
(PCU) min = variable
Update Counter – endif
Could be increment (before update input)
or decrement
where the value of *Print – Print the value that is
the loop control held by minimum
variable is updated → print min
(after endwhile)
Learning outcome (SDS)
2.1 Design a Solution (Pseudocode)
(d) Apply appropriate control structures.
(Repetition: counter-controlled, sentinel-controlled) in computational problem solving.
e) COUNTER-CONTROLLED REPETITION (FREQUENCY)
Initialization – Initial value of the frequency WATCH ME!
→set freq = 0
Quick Access
(before condition)
RULES : Formula – Update the value of
frequency that is held by freq
Three elements that → freq = freq + 1
are required to
(before update counter)
perform frequency
(IFP)
*Print– Print the value that is held by frequency
→ print freq
(after endwhile)
LY2020001226
Learning outcome (SDS)
2.1 Design a Solution (Pseudocode)
(d) Apply appropriate control structures.
(Repetition: counter-controlled, sentinel-controlled) in computational problem solving.
f) SENTINEL-CONTROLLED REPETITION
RULES : Prime Input – Initializes the loop’s control WATCH ME!
variable
Three elements that Quick Access
are required to Condition – Test the loop control
perform counter- variable whether the loop should LY2020001226
controlled continue or stop
repetition
Update Counter – Could be increment or
(PCU) decrement where the value of the loop control
variable is updated
Learning outcome (SDS)
2.1 Design a Solution (Pseudocode)
(d) Apply appropriate control structures.
(Repetition: counter-controlled, sentinel-controlled) in computational problem solving.
g) SENTINEL-CONTROLLED REPETITION (MAXIMUM) WATCH ME!
Initialization – Initial value of the
maximum (set as lowest value)
→set max = 0 / -99999
(before condition)
RULES : Formula - compare the variable Quick Access
with initial value of maximum
Three elements that → if ( variable > max)
are required to
max = variable
perform maximum
endif
(IFP)
(before update input)
*Print– Print the value that is held by
maximum
→ print max
(after endwhile)
LY2020001226
Learning outcome (SDS)
2.1 Design a Solution (Pseudocode)
(d) Apply appropriate control structures.
(Repetition: counter-controlled, sentinel-controlled) in computational problem solving.
h) SENTINEL-CONTROLLED REPETITION (MINIMUM)
Initialization – Initial value of the minimum WATCH ME!
(set as highest value)
→set min = 100 / 99999 Quick Access
(before condition) LY2020001226
RULES : Formula – compare the variable with
initial value of minimum
Three elements that → if ( variable > min)
are required to
min = variable
perform minimum
endif
(IFP)
(before update input)
*Print – Print the value that is held by minimum
→ print min
(after endwhile)
Learning outcome (SDS)
2.1 Design a Solution (Pseudocode)
(d) Apply appropriate control structures.
(Repetition: counter-controlled, sentinel-controlled) in computational problem solving.
i) SENTINEL-CONTROLLED REPETITION (FREQUENCY)
RULES : Initialization – Initial value of the frequency WATCH ME!
→set freq = 0
Three elements that (before condition)
are required to
Formula – Update the value of
perform frequency frequency that is held by freq
→ freq = freq + 1
(IFP) (before update input)
*Print– Print the value that is held by frequency LY2020001226
→ print freq
(after endwhile)