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