← Loops and variables lesson New set →

Electronics Worksheet: Loops and Variables

Electronics lesson 25: Loops and variables · Set 20 · 40 questions
TalentJR

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. 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. 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. 3.🔁 repeat 5 times { repeat 3 times { beep } }
    How many beeps are there?
  4. 4.🔁 total = 0
    for i = 1 to 8 { total = total + i }
    What is total at the end?
  5. 5.🔁 repeat 3 times { repeat 4 times { beep } }
    How many beeps are there?
  6. 6.🔁 count = 0
    repeat 2 times { count = count + 3 }
    What is count at the end?
  7. 7.🔁 count = 5
    while (count < 17) { count = count + 3 }
    How many times does the loop run?
  8. 8.🔁 count = 0
    while (count < 24) { count = count + 3 }
    How many times does the loop run?
  9. 9.🔁 count = 2
    repeat 7 times { count = count + 6 }
    What is count at the end?
  10. 10.🔁 repeat 5 times { repeat 5 times { beep } }
    How many beeps are there?
  11. 11.🔁 x = 2
    repeat 2 times { x = x × 2 }
    What is x at the end?
  12. 12.🔁 x = 4
    repeat 1 time { x = x × 2 }
    What is x at the end?
  13. 13.🔁 count = 3
    while (count < 9) { count = count + 3 }
    How many times does the loop run?
  14. 14.🔁 x = 3
    repeat 3 times { x = x × 2 }
    What is x at the end?
  15. 15.🔁 x = 2
    repeat 5 times { x = x × 2 }
    What is x at the end?
  16. 16.🔁 total = 0
    for i = 1 to 4 { total = total + i }
    What is total at the end?
  17. 17.🔁 repeat 2 times { repeat 4 times { beep } }
    How many beeps are there?
  18. 18.🔁 x = 2
    repeat 4 times { x = x × 2 }
    What is x at the end?
  19. 19.🔁 count = 7
    repeat 8 times { count = count + 9 }
    What is count at the end?
  20. 20.🔁 count = 0
    while (count < 12) { count = count + 4 }
    How many times does the loop run?
  21. 21.🔁 repeat 5 times { repeat 4 times { beep } }
    How many beeps are there?
  22. 22.🔁 count = 3
    while (count < 13) { count = count + 5 }
    How many times does the loop run?
  23. 23.🔁 x = 4
    repeat 5 times { x = x × 2 }
    What is x at the end?
  24. 24.🔁 repeat 6 times { repeat 2 times { beep } }
    How many beeps are there?
  25. 25.🔁 x = 5
    repeat 5 times { x = x × 2 }
    What is x at the end?
  26. 26.🔁 count = 0
    while (count < 8) { count = count + 2 }
    How many times does the loop run?
  27. 27.🔁 count = 0
    while (count < 12) { count = count + 2 }
    How many times does the loop run?
  28. 28.🔁 count = 5
    while (count < 29) { count = count + 3 }
    How many times does the loop run?
  29. 29.🔁 count = 3
    while (count < 43) { count = count + 5 }
    How many times does the loop run?
  30. 30.🔁 repeat 4 times { repeat 5 times { beep } }
    How many beeps are there?
  31. 31.🔁 repeat 6 times { repeat 5 times { beep } }
    How many beeps are there?
  32. 32.🔁 count = 1
    while (count < 22) { count = count + 3 }
    How many times does the loop run?
  33. 33.🔁 x = 1
    repeat 1 time { x = x × 2 }
    What is x at the end?
  34. 34.🔁 count = 0
    repeat 7 times { count = count + 4 }
    What is count at the end?
  35. 35.🔁 count = 8
    repeat 7 times { count = count + 6 }
    What is count at the end?
  36. 36.🔁 total = 0
    for i = 1 to 11 { total = total + i }
    What is total at the end?
  37. 37.🔁 repeat 2 times { repeat 2 times { beep } }
    How many beeps are there?
  38. 38.🔁 x = 5
    repeat 1 time { x = x × 2 }
    What is x at the end?
  39. 39.🔁 x = 1
    repeat 5 times { x = x × 2 }
    What is x at the end?
  40. 40.🔁 count = 3
    while (count < 38) { count = count + 5 }
    How many times does the loop run?

Answer key

  1. adds 1 to count
  2. stores a value
  3. 15
  4. 36
  5. 12
  6. 6
  7. 4
  8. 8
  9. 44
  10. 25
  11. 8
  12. 8
  13. 2
  14. 24
  15. 64
  16. 10
  17. 8
  18. 32
  19. 79
  20. 3
  21. 20
  22. 2
  23. 128
  24. 12
  25. 160
  26. 4
  27. 6
  28. 8
  29. 8
  30. 20
  31. 30
  32. 7
  33. 2
  34. 28
  35. 50
  36. 66
  37. 4
  38. 10
  39. 32
  40. 7

Free electronics lessons, practice and worksheets at talentjr.in/electronics-for-kids