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