Skip to content
Kids
KreerIQ

Debugging: find and fix the bug

Loading…

Free lesson

What you will learn

By the end, you can find a bug by predicting what the code should do, comparing it with what it did, and fixing one line at a time.

Yuki's robot Bolt should walk two squares up, then one to the right, to reach the battery. Instead it turns the other way and bumps into the wall. Yuki does not rewrite everything. She predicts, compares and changes one line. That is debugging.

Read the explanation

A bug is a mistake that makes a program do the wrong thing. To debug it, predict what each line should do. Then run or trace the program and compare: where does the real path split from the plan? That line holds the bug. Fix one thing, then test again.

  • Predict: what should happen after each line?
  • Compare: find the first line that does not match the plan.
  • Fix one thing, then test again.
All tracks