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