Electronics Worksheet: Loops and Variables
Remember (Trace every pass): count = count + k adds k each time round; after n rounds: start + n × k. A loop inside a loop runs outer × inner times. while (condition) repeats until the condition is false — count the rounds as you trace.
NameDateTime takenScore ___ / 40
-
1.🔁 repeat 5 times { repeat 5 times { beep } }
How many beeps are there? - 2.🔁 What does a variable do in a program? (a) stores a value (b) joins two wires (c) blinks an LED (d) measures light
-
3.🔁 repeat 4 times { repeat 4 times { beep } }
How many beeps are there? -
4.🔁 x = 1
repeat 5 times { x = x × 2 }
What is x at the end? - 5.🔁 What does “count = count + 1” do? (a) prints 1 (b) takes 1 away (c) sets count to 1 (d) adds 1 to count
-
6.🔁 x = 5
repeat 1 time { x = x × 2 }
What is x at the end? -
7.🔁 x = 1
repeat 1 time { x = x × 2 }
What is x at the end? -
8.🔁 count = 8
repeat 3 times { count = count + 5 }
What is count at the end? -
9.🔁 x = 4
repeat 4 times { x = x × 2 }
What is x at the end? -
10.🔁 x = 1
repeat 4 times { x = x × 2 }
What is x at the end? -
11.🔁 count = 5
while (count < 21) { count = count + 2 }
How many times does the loop run? -
12.🔁 count = 5
while (count < 29) { count = count + 4 }
How many times does the loop run? -
13.🔁 repeat 3 times { repeat 6 times { beep } }
How many beeps are there? -
14.🔁 count = 5
while (count < 37) { count = count + 4 }
How many times does the loop run? -
15.🔁 total = 0
for i = 1 to 7 { total = total + i }
What is total at the end? -
16.🔁 count = 0
repeat 6 times { count = count + 5 }
What is count at the end? -
17.🔁 x = 4
repeat 5 times { x = x × 2 }
What is x at the end? -
18.🔁 count = 0
while (count < 16) { count = count + 2 }
How many times does the loop run? -
19.🔁 x = 1
repeat 3 times { x = x × 2 }
What is x at the end? -
20.🔁 count = 3
while (count < 7) { count = count + 2 }
How many times does the loop run? -
21.🔁 x = 5
repeat 5 times { x = x × 2 }
What is x at the end? -
22.🔁 total = 0
for i = 1 to 12 { total = total + i }
What is total at the end? -
23.🔁 x = 2
repeat 2 times { x = x × 2 }
What is x at the end? -
24.🔁 total = 0
for i = 1 to 6 { total = total + i }
What is total at the end? -
25.🔁 count = 2
repeat 3 times { count = count + 9 }
What is count at the end? -
26.🔁 count = 1
repeat 6 times { count = count + 4 }
What is count at the end? -
27.🔁 count = 0
while (count < 35) { count = count + 5 }
How many times does the loop run? -
28.🔁 count = 6
repeat 3 times { count = count + 7 }
What is count at the end? -
29.🔁 count = 0
while (count < 12) { count = count + 2 }
How many times does the loop run? -
30.🔁 repeat 3 times { repeat 2 times { beep } }
How many beeps are there? -
31.🔁 count = 0
repeat 10 times { count = count + 9 }
What is count at the end? -
32.🔁 repeat 2 times { repeat 4 times { beep } }
How many beeps are there? -
33.🔁 count = 5
while (count < 17) { count = count + 2 }
How many times does the loop run? -
34.🔁 x = 5
repeat 4 times { x = x × 2 }
What is x at the end? -
35.🔁 x = 2
repeat 1 time { x = x × 2 }
What is x at the end? -
36.🔁 count = 2
repeat 3 times { count = count + 7 }
What is count at the end? -
37.🔁 count = 3
while (count < 27) { count = count + 4 }
How many times does the loop run? -
38.🔁 repeat 2 times { repeat 5 times { beep } }
How many beeps are there? -
39.🔁 total = 0
for i = 1 to 3 { total = total + i }
What is total at the end? -
40.🔁 x = 4
repeat 2 times { x = x × 2 }
What is x at the end?
Answer key
- 25
- stores a value
- 16
- 32
- adds 1 to count
- 10
- 2
- 23
- 64
- 16
- 8
- 6
- 18
- 8
- 28
- 30
- 128
- 8
- 8
- 2
- 160
- 78
- 8
- 21
- 29
- 25
- 7
- 27
- 6
- 6
- 90
- 8
- 6
- 80
- 4
- 23
- 6
- 10
- 6
- 16
Free electronics lessons, practice and worksheets at talentjr.in/electronics-for-kids