Fixing a Bug

A bug in a program is an error in the program’s logic which either prevents or impedes its performance. If a program doesn’t work perfectly, it is said to have a bug, and the programmer is obliged either to fix it or find a way around it.

Most new programmers debug a program by running it, reading the error message and its associated line number, and then examining the source code at the specified line. In many cases, this is enough: messages like RETURN EXECUTED WITH NO GOSUB are fairly simple to fix for a short program.

A programmer can also place trace statements at key points of execution; that is, statements that report what’s happening as the program executes. A PRINT statement can be placed within a conditional to determine whether a condition has proven true or not, or to display the value of variables. A PRINT statement can also be placed in a program loop, to report how many times the loop is being executed.

These debugging methods are fine if they are effective. However, they tend to be tedious to implement, and they involve recompiling the program with each attempt. Using the mvBASIC interactive Debugger, the debugging process becomes simpler and tidier.

Your first experience with the mvBASIC Debugger will probably be the result of an accident, either through a fatal error or because the BREAK key was pressed by mistake. At first, the only thing you need to know about the Debugger is how to get out of it (press END at the Debugger prompt). However, with a little patience you can learn to make the Debugger successfully fine-tune a program.

See Also

Using the mvBASIC Debugger

Debugger Commands: Quick Reference

A Sample Program

Entering the Debugger

Exiting the Debugger

Displaying and Changing a Variable

Accessing Source Code

Using Breakpoints and Tracing

Using Execution Control

Printing Output

Using the Return Stack