π Loops and Repeating Events
In this quiz, you'll explore how loops help us write simpler code by repeating actions instead of writing the same steps over and over. You'll learn to trace code with loops, spot when a loop will stop, and understand how loop variables change each time around. This quiz builds your computational thinking skills for Grade 4 Mathematics. **What you'll learn:** - How to read and trace loops to predict how many times they repeat - When to use a loop instead of writing code multiple times - How loop variables and conditions control when a loop stops - Basic patterns like counting loops and nested loops
Questions in this quiz
Answers hidden β play to find out.
- Question 1
Look at the following code. How many times will the word 'Hello' be printed?
for i = 1 to 5 do print 'Hello' end
- Question 2
A loop is useful when you need to repeat the same code many times.
- Question 3
Which of these loops will repeat exactly 3 times?
- Question 4
Look at the following code. What will be printed?
count = 1 while count β€ 3 do print count count = count + 1 end
- Question 5
When you write a for-loop from 1 to 10, it will always run exactly 10 times.
- Question 6
You want to print the numbers 2, 4, 6, 8, 10. Which loop would work best?
- Question 7
Look at the following code. How many stars will be printed?
for row = 1 to 3 do for col = 1 to 4 do print '*' end end
- Question 8
A while loop must have a condition that eventually becomes false, or it will loop forever.
- Question 9
What is wrong with this code?
while x > 0 do print 'Hello' end
- Question 10
You need to print the numbers 10, 9, 8, 7, 6, 5. Which loop would you use?
- Question 11
Look at the following code. What is the value of 'sum' after the loop ends?
sum = 0 for i = 1 to 4 do sum = sum + i end
- Question 12
If a loop's condition is 'while x < 10' and x starts at 1, the loop will stop when x reaches 10.
- Question 13
Why would you use a loop instead of writing the same code line many times by hand?
- Question 14
Look at the following code. What does it do?
for i = 1 to 5 do print i * 2 end
- Question 15
A for-loop is better than a while loop for counting from 1 to 100.
- Question 16
Look at the following code. When does the loop stop?
x = 5 while x > 0 do print x x = x - 1 end
- Question 17
Which code would print 'Done' only once after the loop finishes?
A) for i = 1 to 3 do print 'Done' end
B) for i = 1 to 3 do print 'A' end print 'Done'
- Question 18
Look at the following code. What number will be printed last?
for i = 10 to 15 do print i end