Programming constructs - CCEAIteration

Computer programs use data stores to organise the different types of data they contain. Data stores can be either a constant, variable or an array, and contain inputs, outputs, functions, instructions, sequences and more.

Part ofDigital Technology (CCEA)Digital development concepts (programming)

Iteration

There may be times when you want the computer to repeat a set of instructions. The repetition of instructions is called .

We can place the instructions we want to repeat inside a loop. You may want to repeat the instruction for a set number of times (FOR loop) or until a condition is met (WHILE loop).

FOR loops are often referred to as count controlled loops and WHILE loops as condition controlled loops.

Example: Count controlled iteration (FOR loop)

print("I can count to 5!")
for i in range(6): print("Number" + str(i))

Outputs:

I can count to 5!
Number 0
Number 1
Number 2
Number 3
Number 4
Number 5

Example: Condition controlled iteration (WHILE loop)

print("I can count to 5!")
i = 0
while i <6: print("Number" + str(i)) i = i + 1

Outputs:

I can count to 5!
Number 0
Number 1
Number 2
Number 3
Number 4
Number 5