Class 6 Computer Science — Repeating with loops
Read a loop, work out how many times it runs, and follow the value it builds up to the end.
Name: ________________________
1.A program sets a total to 0. It repeats this 3 times: add 10 to the total. What is the total at the end?
2.A program sets a total to 100. It repeats this 5 times: take 20 away from the total. What is the total at the end?
3.Follow this code by hand. What is total at the end?
total = 0 for i in range(0, 4): total = total + 64.A program needs to print a star one hundred times. Why is a loop better than writing the printing step out one hundred times?
- a) It makes the stars appear in a different order
- b) Loops are the only way a computer can print anything
- c) It is far shorter, and changing the number changes it everywhere at once
- d) It uses one hundred times less memory to store a star
5.A program sets a total to 7. It repeats this 4 times: add 2 to the total. What is the total at the end?
6.A program repeats this 4 times: print 3 stars. How many stars are printed?
7.A program sets a total to 0. It repeats this 5 times: add 4 to the total. What is the total at the end?
8.A program sets a number to 2, then doubles it three times over. Put the values the number holds in order, from the start to the end.
- 4
- 16
- 8
- 2
Answer key — Class 6 Computer Science — Repeating with loops
- 1. 30
- 2. 0
- 3. 24
- 4. c) It is far shorter, and changing the number changes it everywhere at once
- 5. 15
- 6. 12
- 7. 20
- 8. 1. 2 2. 4 3. 8 4. 16