One way to introduce the concept of debugging is to begin with a definition:
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware thus making it behave as expected.
The definition assumes that the code you write has bugs, which isn’t the case, is it? Next chapter!
For the rest of us still here, figuring out what’s happening inside your running code is the best way to understand how to get it back to working the way it’s expected to work.
A lot has been written on the fine art of tracking down bugs. It takes intuition, a good knowledge of the particular code you’re working on, and enough experience ...