Monitor the program during execution, checking the contents of key variables. Use structured programming to write your code. If you work on another person's code, try to find the assertions. These usually lead the way to understanding and debugging the code. Rewrite bad code, and write and test code in small pieces.
Errors are most frequent on boundary conditions.
When verifying code, check that the boundary conditions are what you expect. Make sure all variables are initialized before use. Test programs at their boundary values.