Part 1 · Module 2
Trace code in your head
Run code in your head with a trace table. Learn loop boundaries, break, continue, early return, and the usual reasons tests fail.
4 lessons · 41 min in total
When to reach for it
- Trace table
- When you're not sure what a loop does. Pick a small input that still makes the loop run two or three times.
- Check the loop bounds
- Every time you write a loop. Trace just the first and the last round, since boundary bugs always live there.
- Early return
- When the answer is already certain in the middle of the loop. Return inside the loop, and put the "not found" answer after it.
- Before you submit
- Every time a test fails but your logic feels right. Check these three things first.
Lessons
Module challenge
Coding problems that test every pattern in this module.