← Loops and variables lesson New set →

Electronics Worksheet: Loops and Variables

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

Answer key

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

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