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