Studyfin Studyfin ✨ Sign up free

Lists & arrays

Grade 9 · Coding · Free lesson

Hey there! Ready to learn how programmers organize data? Let's explore lists and arrays together!

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

check list

Each item in a list has a position number called an index. In coding, we almost always start counting our indexes at zero.

"Apple" Index 0 "Banana" Index 1 "Cherry" Index 2 Reading

To design smart programs, we use a software design process. We break a big task into smaller steps, like finding an item or updating a value.

spanish

We can use nested loops to search through grids of data. The outer loop checks each row, while the inner loop checks each item in that row.

Outer Loop: Row by Row Inner Loop: Item by Item
✏️ Worked example

You want to store your daily step counts for three days and find the day with the highest steps. Let's design a program to solve this.

  1. Identify the subproblems: First, store the step counts. Second, look at each count one by one. Third, track the highest value.
  2. Create a list named 'steps' with three values: [4000, 8500, 6200].
  3. Assign index numbers to the list: 'steps[0]' is 4000, 'steps[1]' is 8500, and 'steps[2]' is 6200.
  4. Create a variable named 'max_steps' and set it to the first item (4000).
  5. Use a loop to check the remaining items. Compare each item to 'max_steps'.
  6. Since 8500 is larger than 4000, update 'max_steps' to 8500. The final highest step count is 8500 at index 1.
spanish
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons