Bugs are just mistakes, while debugging you should learn from your mistakes and list them.
- Write a pseudocode and list all the edge cases.
- keep your code splitted into chunks with an explainatory comment on top of each one.
- While debugging use comments to disable your code part by part to locate the bug.
- List your common bugs.
- Dealing with zero-based numbering can be troublesome. You either convert everything entered by input to zero-base (which is prefered) or you resize the array and ignore the first element of the array.
- Check edge cases.
- Check ( = / == ) is it boolean '==' or declaring '='.
- Check position of variables declaration: always declare variables when you'll use them immediately.