← Loops and variables lesson New set →

Electronics Worksheet: Loops and Variables

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

Answer key

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

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