7.6 — When you're stuck, do this
Read one box at a time. No rush.
A step-by-step plan#
- Read the error slowly. What line? What word?
- Make it smaller. Remove code until the problem is tiny and easy to see.
- Print values (or use the debugger) to see what's really happening.
- Explain it out loud, line by line, to a friend — or a rubber duck. You'll often find the bug halfway through.
- Take a break. A short walk really does help. Fresh eyes spot bugs fast.
- Search the exact error message online.
- Ask for help with a small example, the exact error, and what you've tried.
Rubber duck debugging
Explaining your code to an object (like a rubber duck) line by line. Saying it out loud makes you notice what you skipped over in your head.
Write code in small steps#
The best way to avoid getting stuck: write a few lines, compile, run, check. Then add a few more.
If you write 200 lines before running anything, you'll have 20 bugs tangled together. If you write 5, you'll have at most one.
Good habit
Compile and test often. Small steps, small bugs.
Tip: press ← / → to move between lessons, / to search.