CLEAR Statement

The CLEAR statement assigns a value of 0 to all variables throughout the program.

Format

CLEAR

Description

The CLEAR statement is generally used at the beginning of a program to set all previously assigned and unassigned values of variables to zero. This procedure avoids run-time errors for unassigned variables. If the CLEAR statement is used later in the program, any values that have already been assigned to variables (including array variables) are lost.

The CLEAR statement cannot be used to initialize only selected variables. If it is used, all variables in the program are initialized to 0.

NOTE

The CLEAR statement is often used to prevent the run-time warning message which normally ensues when an unassigned variable is used. This practice, however, is not always desirable, since the unassigned variable message may be useful in detecting programmer errors (such as misspelled variable names).

Example

In this application the CLEAR statement is used at the beginning of the program to initialize variables. Thus, when the previously unused variable STOPNOW is used as the loop control, no error message ensues.

CLEAR

   .

   .

   .

LOOP UNTIL STOPNOW DO

   .

   .

   .

   PRINT "DO YOU WANT TO STOP (Y OR N)" :

   INPUT ANSWER,1                         

   IF ANSWER = "Y"  THEN STOPNOW = 1              

REPEAT

See Also

Statement and Function Reference