user446654
user446654

Reputation: 1141

How can I debug my code?

I asked about some non-working code I had at Code works extremely slowly and does not print output.

As you can see in the answer to that question, deks debugged my code and also provided the output of the fib() function. How could I do that by myself? I really know very little about debugging.

Upvotes: 1

Views: 501

Answers (1)

Leo Izen
Leo Izen

Reputation: 4289

To debug, get yourself and IDE like NetBeans or Eclipse. Then instead of clicking run, click on line number then click debug. When the execution gets to this point, it stops, and you can examine the variables that are currently visible. To make sure they have values they should have. For example, if n should be between 1 and 10, and it is 100, then you know something is wrong. Fine where you set n, and add more breakpoints. These are the points were the execution will stop. You can also click step over, to execute the next line, then stop, or step into, which will execute the next line, except it will step into any functions that you used.

Upvotes: 3

Related Questions