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.🔁 What does a variable do in a program? (a) measures light (b) blinks an LED (c) joins two wires (d) stores a value
- 2.🔁 What does “count = count + 1” do? (a) prints 1 (b) sets count to 1 (c) takes 1 away (d) adds 1 to count
-
3.🔁 x = 3
repeat 3 times { x = x × 2 }
What is x at the end? -
4.🔁 x = 5
repeat 1 time { x = x × 2 }
What is x at the end? -
5.🔁 count = 7
repeat 6 times { count = count + 6 }
What is count at the end? -
6.🔁 x = 4
repeat 2 times { x = x × 2 }
What is x at the end? -
7.🔁 count = 8
repeat 2 times { count = count + 6 }
What is count at the end? -
8.🔁 repeat 2 times { repeat 2 times { beep } }
How many beeps are there? -
9.🔁 x = 1
repeat 2 times { x = x × 2 }
What is x at the end? -
10.🔁 total = 0
for i = 1 to 5 { total = total + i }
What is total at the end? -
11.🔁 count = 1
while (count < 13) { count = count + 4 }
How many times does the loop run? -
12.🔁 count = 4
repeat 8 times { count = count + 5 }
What is count at the end? -
13.🔁 total = 0
for i = 1 to 3 { total = total + i }
What is total at the end? -
14.🔁 total = 0
for i = 1 to 11 { total = total + i }
What is total at the end? -
15.🔁 count = 4
repeat 7 times { count = count + 7 }
What is count at the end? -
16.🔁 count = 0
while (count < 16) { count = count + 4 }
How many times does the loop run? -
17.🔁 count = 10
repeat 7 times { count = count + 10 }
What is count at the end? -
18.🔁 count = 5
while (count < 17) { count = count + 2 }
How many times does the loop run? -
19.🔁 x = 4
repeat 1 time { x = x × 2 }
What is x at the end? -
20.🔁 count = 0
repeat 9 times { count = count + 7 }
What is count at the end? -
21.🔁 repeat 5 times { repeat 3 times { beep } }
How many beeps are there? -
22.🔁 x = 3
repeat 2 times { x = x × 2 }
What is x at the end? -
23.🔁 repeat 3 times { repeat 6 times { beep } }
How many beeps are there? -
24.🔁 repeat 5 times { repeat 5 times { beep } }
How many beeps are there? -
25.🔁 x = 4
repeat 5 times { x = x × 2 }
What is x at the end? -
26.🔁 count = 2
while (count < 26) { count = count + 4 }
How many times does the loop run? -
27.🔁 repeat 6 times { repeat 6 times { beep } }
How many beeps are there? -
28.🔁 total = 0
for i = 1 to 7 { total = total + i }
What is total at the end? -
29.🔁 total = 0
for i = 1 to 4 { total = total + i }
What is total at the end? -
30.🔁 x = 3
repeat 1 time { x = x × 2 }
What is x at the end? -
31.🔁 total = 0
for i = 1 to 10 { total = total + i }
What is total at the end? -
32.🔁 count = 7
repeat 8 times { count = count + 2 }
What is count at the end? -
33.🔁 repeat 3 times { repeat 3 times { beep } }
How many beeps are there? -
34.🔁 repeat 5 times { repeat 4 times { beep } }
How many beeps are there? -
35.🔁 x = 5
repeat 5 times { x = x × 2 }
What is x at the end? -
36.🔁 count = 4
repeat 7 times { count = count + 6 }
What is count at the end? -
37.🔁 total = 0
for i = 1 to 12 { total = total + i }
What is total at the end? -
38.🔁 count = 9
repeat 5 times { count = count + 6 }
What is count at the end? -
39.🔁 count = 2
repeat 9 times { count = count + 2 }
What is count at the end? -
40.🔁 count = 1
while (count < 21) { count = count + 4 }
How many times does the loop run?
Answer key
- stores a value
- adds 1 to count
- 24
- 10
- 43
- 16
- 20
- 4
- 4
- 15
- 3
- 44
- 6
- 66
- 53
- 4
- 80
- 6
- 8
- 63
- 15
- 12
- 18
- 25
- 128
- 6
- 36
- 28
- 10
- 6
- 55
- 23
- 9
- 20
- 160
- 46
- 78
- 39
- 20
- 5
Free electronics lessons, practice and worksheets at talentjr.in/electronics-for-kids