Repetition & Iteration (Edexcel GCSE Computer Science)
Revision Note
Repetition & Iteration
What is the difference between repetition and iteration?
Repetition is executing the same instructions whilst a condition is True
Iteration is is executing the same instructions until all items in a data structure have been processed
Repetition & iteration are both examples of loops
Repetition
Python examples | |
---|---|
| The instructions inside the loop repeat until the A higher starting number would result in more repeating |
| Whilst the user does not input a "Y" to accept the terms & conditions the question is repeated infinitely |
Iteration
Python examples | |
---|---|
| Outputs the values of the scores array, multiplied by 2 on separate lines |
| The for loop processes each student in the students table. In each loop the individual fields are outputted. The output from this loop is: Name: Bob Test score: 78 Name: Fred Test score: 24 Name: Julie Test score: 32 |
Repetition & iteration can be further confused with the addition of different types of loops
Type of loop | Description |
---|---|
Count-controlled | The number of loops is already known or can be determined before the loop starts |
Condition-controlled | The number of loops is not known, it continues until the condition is True |
Python example | Repetition or iteration? | Type of loop? |
---|---|---|
| Repetition | Condition-controlled |
| Repetition | Count-controlled |
| Iteration | Count-controlled |
In Python, when the
range()
function is used, the loop is count-controlledIf the loop is used to access a data structure it is iteration
Examiner Tip
If the word 'iteration' is used in an instruction, you can use a 'for' loop to process a data structure.
If the word 'repetition is used in an instruction, you must choose whichever construct ('for', 'while') is suitable for the program
Last updated:
You've read 0 of your 10 free revision notes
Unlock more, it's free!
Did this page help you?