Loops Inside Loops: The Power of Nested Loops
1 of 4ICT · My World Quest — full scheme of work · explorer
Loops Inside Loops: The Power of Nested Loops
For grown-ups
Companion summary
Have you ever watched a washing machine run a full cycle, then start all over again with a new load? Game designers use nested loops every day to draw grids, spawn enemies in rows, and build whole worlds automatically. A single nested loop can draw a 10 by 10 grid of squares using just a few lines of code instead of one hundred. When you finish, try changing the inner loop number and see what shape your pattern makes next.
Warm-Up: Think About Repeating
Warm-Up: Think About Repeating
Imagine you are stamping stars onto paper. You stamp 3 stars on one row, then move down and stamp 3 more stars on the next row, then again on the next row. You end up with 3 rows of 3 stars — that is 9 stars in total! You did two sets of repeating: repeating stars across, AND repeating rows down. In coding, we use loops to repeat actions. Today you will discover what happens when you put one loop INSIDE another.
💭 Think about this
Can you think of anything in real life where you repeat something, and then repeat THAT thing again? (For example: clapping 4 times, then doing that 3 times in a row.)