Loops Lesson
Loops Lesson
Problem Solving
Grade 11
OBJECTIVES
By the end of the lesson students should
be able to:
State the difference between definite and
indefinite loops
Differentiate among the three types of loop
structures ( For loop, While loop and repeat until)
Classify each loop structure as definite and
indefinite.
Include for loops structures in a pseudocode
algorithm.
WHAT ARE LOOPS?
Loops are constructs used for repeating
parts of a program. That is, they will
repeatedly execute a section of a program until
a condition is satisfied.
LOOPS SIMPLIFIED
https://www.youtube.com/watch?v=w
xds6MAtUQ0
THE TWO TYPES OF LOOPS
While-Do
Repeat Until
STRUCTURE OF A LOOP
The basic structure of a loop is:
Initialization
Loop Header
Conclusion
INITIALIZATION
Loops use a variable to control the amount
of iterations. We need to initialize the variable
to a start value or read an initial value into the
variable.
LOOP HEADER
It states the type of loop as well as a logical
test against the controlling variable. It may
have the initialization if it is a FOR loop.
LOOP BLOCK
We must specify what statements are to be
repeated by the computer. The repetitive
statements are normally placed in the loop
block.
CONCLUSION
This is simple keywords to signify the end of
the loop structure.
FOR LOOP
The FOR loop is usually used to represent
definite loops.
FOR LOOP
The FOR Loop syntax is shown below:
sum 0
Avg0
num 0 { initialization }
START
STOP
FOR LOOP FLOWCHART WITH
EXAMPLE
WHILE LOOP AND REPEAT UNTIL
The While-Do and the Repeat-Until can be
used to represent both indefinite & definite
loops. The Repeat until is a loop that tests a
condition at the end of the loop so the
statements in the loop will always be
executed at least once.
REPEAT
Statement 1
Statemnet 2
…
UNTIL <condition statement>
SOLVE THE FOLLOWING
Write a pseudocode algorithm to set the
password to a door system to 3718. The
pseudocode should prompt the user for the
password until the correct password is
entered.
SOLVE THE FOLLOWING
Use the appropriate loop structure to write the following
pseudocodes: