← Loops and variables lesson New set →

Electronics Worksheet: Loops and Variables

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

Answer key

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

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