▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
AI angle: ask AI to trace a loop
Get AI to walk through code step by step, then check it yourself.
🎬 Video version coming soon — read it now
Tracing means following code step by step and writing down what each variable holds after each line. It's the single best way to understand loops, and AI can help you practise it.
Trace it yourself first
Write down a trace on paper:
Prediction: it prints 6. Now run it to check.
Then ask AI to trace it
Compare the AI's trace with yours. Where they differ, find out who is right by adding print(i, total) inside the loop and running it.
Why the code beats the chatbot
Language models predict text; they don't actually run your code (unless the tool says it is running code). They are usually right on short loops but can slip on longer ones, especially with off-by-one details like range(1, 5). Running the code is the final answer, every time.
More useful prompts
In one line
Trace loops on paper, ask AI to trace them too, and settle any disagreement by running the code.
Share with a friend