BREAK Statement

The BREAK statement allows the Break Inhibit Counter of a program to be incremented or decremented, thus controlling access to the Debugger.

Format

BREAK[KEY] ON | OFF

Parameter(s)

ON

Decrements the Break Inhibit Counter by 1.

OFF

Increments the Break Inhibit Counter by 1.

Description

While a program is being executed, pressing BREAK normally transfers control from the program to the Debugger. The BREAK statement gives the programmer control over this feature.

The BREAK statement does not directly toggle the BREAK feature on and off, but increments and decrements the Break Inhibit Counter. The counter is usually set to 0, meaning that the BREAK feature is enabled. Each BREAK OFF statement increments the counter by 1, and each BREAK ON statement decrements the counter by 1. When the counter is set to any number other than 0, the BREAK feature is off. Thus if two BREAK OFF statements have been used in a program, the counter is set to 2, and two BREAK ON statements are necessary to return the counter to 0 and re-enable the BREAK key.

Using a counter instead of directly turning BREAK on and off simplifies situations where a program calls another program or external subroutine. Using a counter ensures that the status of the BREAK key in the calling program is maintained. This, of course, is dependent on each BREAK OFF statement being paired with a BREAK ON statement before the end of the program or subroutine.

During a SLEEP or RQM statement, pressing BREAK not only enters the Debugger but also disables the sleep. If the Break Inhibit Counter is set, the Debugger is not entered, but the sleep statement is still interrupted. Thus the BREAK key may also be used to terminate unwanted sleeps during the execution of a program.

The Debugger may also be entered through a run-time error or by encountering a DEBUG statement. See Using the mvBASIC Debugger for more information.

Examples

To turn the break feature off for a program, the code would read:

BREAK OFF

At the end of the program, the break feature may be reinstated with:

BREAK ON

In the next application, a quiz program gives 60 seconds for the user to answer a question. To answer the question before the time is up, the user is allowed to press BREAK. A BREAK OFF statement is used to turn off the debugging feature of the BREAK key during the sleep, so that pressing BREAK interrupts the sleep but does not enter the Debugger. The INPUTIF statement is used after the sleep to examine the type-ahead and determine if a response was entered.

ITEM = RND(99)

READ QUESTION FROM QUESTFILE,ITEM ELSE

   PRINT "ERROR IN READING " : ITEM

   STOP

END

PRINT @(0,23) : "ENTER ANSWER, PRESS ENTER AND

BREAK." :

PRINT QUESTION <1> :

BREAK OFF

SLEEP 60

BREAK ON

INPUTIF ANSWER THEN

   GOSUB EVAL

END ELSE

   PRINT @(-1) : "NOT ANSWERED IN TIME. -3

   POINTS."

   POINTS - = 3

END

See Also

Statement and Function Reference