For some kinds of programs, it is possible to write a program that does part of the job, then gradually expand it to do more. Take a wider view and look at other things. Sometimes students stay up all night trying to reason about why their program does not work, when a simple printout would make the problem obvious. You can also stop your program and get variable values using an error call. When you get an error break, try the Command menu at the top of the screen.
Expression prints the expression in which the error occurred.
Backtrace shows the sequence of calls leading to the point of the error. Procedure prints the code of the current procedure. List Variables prints the values of variables in the current stack frame. Then you can examine its variable values, etc. Next Frame moves the level of the stack that is being examined to the next frame.