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