Studyfin Studyfin ✨ Sign up free

Lists & arrays

Grade 7 · Coding · Free lesson

Hey there! Today we are going to explore how programmers organize data using lists, and how we can use a software design process to solve real-world problems with loops!

A list, or an array, is like a row of labeled boxes. It lets us store many items together in one single place under one name.

To solve big coding problems, we use a software design process. We break the main problem into smaller subproblems, like creating a list first, and then using nested loops to search through it.

Subproblem 1Subproblem 2

A nested loop is simply a loop inside another loop. The outer loop runs once, and then the inner loop runs completely before the outer loop moves to its next turn.

LOOPS
✏️ Worked example

We want to design a program that prints a weekly schedule. It must print 'Day 1' through 'Day 3', and for each day, print 'Activity A' and 'Activity B'. Let's explain and design this using nested loops!

  1. Identify the subproblems: Subproblem 1 is tracking the days. Subproblem 2 is listing the activities for each day.
  2. Write the outer loop to repeat 3 times, once for each day (Day 1 to Day 3).
  3. Write the inner loop inside the outer loop to run 2 times, once for each activity (A and B).
  4. Trace the code: When Day is 1, the inner loop runs for Activity A, then Activity B. Then Day becomes 2, and the activities run again!
  5. Combine the loops into a text-based program to print the complete schedule.
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons