Specifications

Program debugging - 1
PROGRAM DEBUGGING
CAMBASIC has several constructs which can be used to debug a program. This section will outline the methods and give
examples.
Using the STOP statement
When a STOP statement is encountered, program execution halts and the line number containing the stop statement is
displayed.
By inserting the STOP statement in different sections of the program, you can determine whether these sections are being
executed. For example, you can test a conditional branch:
10 INPUT A
20 IF A=2 THEN 50 ELSE 80
30 '
40 '
50 B=23
55 STOP
60 '
70 B=25
75 STOP
80 '
In this example, a line number followed by a remark ( ' ) statement means that this line would be a part of your program.
In the example above, STOP statements are inserted at lines 55 and 75 to determine if the branch at line 20 is operating
correctly. When you input 2, the program should stop at line 55. Otherwise, it should always stop at line 75.
USING THE PRINT AND INPUT STATEMENTS
The example above shows how the INPUT statement can be inserted so that you can manually change the value of X to test
this program fragment.
The PRINT statement can also be used to print out the value of any variable or memory location after the program has
halted.
TRON/TROFF TRACES EXECUTION PATHS
TRON turns on the line number tracing function. Line numbers are printed as they are executed. No other information is
printed. However, all PRINT statements execute properly. Because the line numbers are printed, execution is slowed. The
slowdown is less noticeable at higher baud rates. To turn the trace off, execute TROFF.
Use TROFF to turn off the trace function. These two statements are most useful when tracing portions, rather than entire
programs. Below is a test program:
10 A$ = "Down"
20 TRON
30 FOR X = 0 TO 2
40 GOSUB 90
50 NEXT
60 TROFF
70 END
80 S = 0