π Lists & Loops

Say you had 100 coins to collect. You would notwrite βcollect coin 1, collect coin 2, collect coin 3β¦β a hundred times β that's bananas. π There's a much smarter way.
Put all the coins in a list, then use a loop to run one rule on every single one.
The big idea: one rule, the whole list
A list is just a row of boxes that holds a bunch of things β all your coins, all your enemies, all the blocks in a level. Instead of a separate name for each, they live together in one list.
A loop is how you deal with the whole list at once: βfor eachthing in the list, do this.β You write the rule a single time, and the loop runs it on every item β 3 of them or 3 million. That's how one tiny bit of code can move a thousand stars or check a whole world.
Your turn: run a rule down a list
Watch the glowing cursor β that's the loop β walk the list and do the job to each coin. Make the list longer, switch the job, and notice you never have to write a second rule.
One rule, written once β the loop runs it on every coin, however many there are.
π How long is the list?
π§ The job
β‘ Loop speed
Discovery missions
Try each one, tick it off, then peek at the secret.
πRun the loop with 5 coins and watch the glowing cursor. What does it do at each coin?
πSlide the list up to 12 coins and run it again. Did you have to add any new rules for the extra coins?
πSwitch the job to Paint and run. The job changed β but did the loop change?
π€―Imagine the list had ONE THOUSAND coins. How much more code would you write?
πͺRemember collecting coins in your game. How do you think it checked all of them?
π New thinking tool unlocked! You now know:
- π A list is a row of boxes that holds many things.
- π A loop visits each item and runs the same rule on it.
- βοΈ You write the rule ONCE β it works for 3 items or 3,000.
- π§© The loop and the job are separate β mix and match them.
- πͺ Your game's coins were a list it looped over every frame.