If your program gets to a part that it should not, utilize break points. Let’s say your program should not be on line 56, but it is. You have to locate the closest branch point (usually a conditional statement) that can mistakenly lead the program to line 56. Insert a break point on the first line of the conditional statement.
If variables involved in the condition of the conditional statement have been changed, you may need to stop the program and run it again to find out why the wrong decision was made. Otherwise, you can inspect variables to find out why the wrong decision is made.
If you verify that the paused conditional statement makes the right decision with all the variables with expected values, then you need to move the break point down further to inspect nested conditional statements.