What is debugging?

Sometimes, when you write a program, you do not get the correct result, even if you think you have coded everything as it should be. Then you have to somehow trace the code to find out where the possible cause is. One way is to use writeln's everywhere possible in order to find out if the procedure or loop has been entered. Another much better and professional way is to use the debugger Turbo Pascal or Borland Pascal supplies. With this debugger you can watch how the variables change and which statements are executed at which time, and what the action of the program at that instant is.

How do I Debug a Pascal Program?

This will only help you if you are using Turbo™ or Borland™ Pascal. Suppose you have written the whole program or part of it, it is always better you write a part of the program then test it and write another part and so on, that way you do not face all errors at once and can solve them easier. Normally you press Ctrl + F9 to run your program. Now you will only press F7 and if it compiles you will see a blue line within your program, which means that the execution has begun and is now at that line. Each F7 executes one line further. F8 does the same, except that it does not enter procedures and functions. If you press Alt+F5 together, then you can see what the output of the program has been until now. If you want to watch the state of a variable, you should go to the debug file menu of pascal and choose watch. This is done by pressing ALT+D and then W. Then press INSERT and write the name of the variable to be watched

Below is a screenshot of a program, deciding whether the input is larger than 10 or not, being.traced. The state of the variable i is being watched.

Screenshot of a trace

After another F7 or F8, you will get to the end of the program, if you now press ALT+F5, you will get this screen to see :

Screenshot of the output of a program
  

A First Look A First Look at Pascal Basic Input/Output Identifiers & Types
Constants Standard Functions If..Then Statement Case Statement
Repetitions Procedures and Functions Enumerated /Subrange Types Sets
I/O, Text Files Arrays Records Recursion
Pointer How to Debug Previous Exam Questions Advanced
ASCII Code Table Homepage University Homepage Computer Engineering Dept.