← Loops and variables lesson New set →

Electronics Worksheet: Loops and Variables

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

Answer key

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

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