Grade 8 · Media & Informatics
Store many values in a list and step through its items with a loop.
Programs rarely handle just one value — they handle many. A data structure is a way of organising data so that a program can use it well. The most common is a list: an ordered collection of items, like a shopping list or the high scores in a game.
In most languages the items in a list have a position, called an index, and counting often starts at 0: the first item is at index 0, the second at index 1, and so on. Knowing the index lets a program read or change exactly the item it wants.
Lists are powerful because a loop can step through every item in turn — 'for each name in the list, show it'. Storing related data together in a list, instead of in dozens of separate variables, keeps programs short and clear.
Have a go right here. Nothing is saved and you can retry as much as you like. Create a free account when you want to save your progress and get Archie, your tutor.
Create a free account to save your progress, track mastery and ask Archie, your tutor, for a hand.
Already with us? Open this lesson in learncoach.ch for mastery tracking and Archie, your tutor.