← Loops and variables lesson New set →

Electronics Worksheet: Loops and Variables

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

Answer key

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

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