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