← Loops and variables lesson New set →

Electronics Worksheet: Loops and Variables

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

Answer key

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

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