Grade 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.Follow this code by hand. What is total at the end?
total = 0 for i in range(0, 4): total = total + 62.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.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.
- 2
- 8
- 4
- 16
4.Each of these starts a total at 0. Match each loop to the total it ends with.
- Repeat 3 times: add 5
- Repeat 4 times: add 5
- Repeat 3 times: add 7
- Repeat 2 times: add 9
- Repeat 5 times: add 2
- 21
- 20
- 15
- 18
- 10
5.A program repeats this 6 times: print a star. How many stars are printed?
6.A program sets a total to 0. It repeats this 3 times: add 8 to the total. What is the total at the end?
- a) 11
- b) 8
- c) 3
- d) 24
7.A program sets a number to 3. It repeats this 3 times: double the number. What is the number at the end?
8.A program sets a total to 0. It repeats this 3 times: add 10 to the total. What is the total at the end?
Answer key — Grade 6 Computer Science — Repeating with loops
- 1. 24
- 2. 0
- 3. 1. 2 2. 4 3. 8 4. 16
- 4. Repeat 3 times: add 5 → 15; Repeat 4 times: add 5 → 20; Repeat 3 times: add 7 → 21; Repeat 2 times: add 9 → 18; Repeat 5 times: add 2 → 10
- 5. 6
- 6. d) 24
- 7. 24
- 8. 30