Index Ai Academy
Phase 0 · Tools · Python core

Loops

Repeat work over every item without copy-pasting code.

About 25 minutes · Free lesson

Start this lesson

Why it matters

AI work is repetitive in exactly the way computers are good at: score 500 headlines, send 20 prompts and compare the answers, process every row of an export, run an evaluation over a test set. When you train a neural network in Phase 4, the training itself is a loop that runs thousands of times. Loops are how you say "do this for each one" once, instead of copying code.

What you'll be able to do

  • Repeat code for every item in a list with a for loop
  • Use the accumulator pattern to total, count and track the best item
  • Filter items into a new list with if inside a loop
  • Use range, enumerate, zip, while, break and continue

Before this lesson

Next in this phase: Dictionaries