Loops Mrs
Loops Mrs
Loops Mrs
MRS. PALMER
There are three categories of
control structures.
Sequential Statements
Conditional Branching
statements
Iteration/ Looping
TYPES OF LOOPS
There are various types of Loops, two out of three will be covered in
Grade 10 are;
For
While
Repeat until
FOR LOOPS – repeats instructions a
predetermined number of times . E.g
10-100 times.
Step 2
Place the For statement before
For the instructions to start and
Read A,B,C endfor to end the instructions.
Sum=A+B+C
Average=Sum/3
Print “Average”, Average
EndFor
HOW TO CONSTRUCT A FOR LOOP
Step 3 Determine what instructions are
to be repeated and use a new
For S=1 to 25 Do variable as the loop variable.
Read A,B,C
Sum=A+B+C
Average=Sum/3
Print “Average”, Average
EndFor
STEP CLAUSE
This indicates how much the loop variable is to be increased or
decreased by each time the loop is executed.
E.g. E.g with a step clause:
FOR num=1 TO 5 Do
Print num FOR i=10 TO 0 step -2 DO
END FOR Print i
END FOR
The computer would display: The computer would display:
1 10
2 8
3 6
4 4
5 2
0
x=1
NO
For x = 1
to 10 do
YES
Hello
world
stop
ACTIVITY
Answer the following questions by writing the IPO chart and
Pseudocode;
1. Write a structured algorithm that prints the message “Are we
there yet” 100 times.
2. Write a structured algorithm that reads the marks obtained by 30
students in a test given that the pass mark is 50 and for each
mark prints whether the person passed or failed.
3. Write a structured algorithm that prints the even numbers between
2 and 20.