Available on:
Alias: CLR

CLEAR

The CLEAR command serves two purposes: the primary semantics of the CLEAR command is to re-initialize (integers) variables to their starting values. Which are usually zero but, of course, can be different from zero. At the moment, their starting value is equal to the assignment during the definition. Other data types (like FLOAT or BIT) are not re-initialized. This is especially useful at the beginning of a program to ensure that there are no residual values from previous executions.

The other semantics, which is expressed through the numeric parameter, is related to the space occupied by the strings. This space is fixed and is used as a sort of dynamic "heap". The numeric parameter provides, in fact, the maximum size allocated for the strings. This value is equivalent to assigning a value with the DEFINE STRING SPACE pragma. Dynamic strings are reinitialized to empty strings with this command, too.

The criterion of the size given with this parameter should be to minimize the memory footprint in order to leave as much space as possible to the code and resources (which shares the same data area). In other words, assuming that the available space in the target is 32 KB, and the code and graphical resources occupies 20 KB, and that we choose to use the default value on the number of dynamic strings for the target (e.g. n=128), the maximum value to give to CLEAR will be 32KB - 20KB - (4*n) = 11776 / 2 = 5.888 bytes.

SYNTAX

 CLEAR size


Legend
  • id : identifier
  • type : datatype
  • v : value
  • "..." : string
  • [...] : optional

EXAMPLE

 CLEAR 2048


ABBREVIATION: Clr

Join BASIC 10Liner Contest with ugBASIC!

An interesting competition is held at the beginning of each year: the BASIC 10Liner Contest. It is possible to use ugBASIC to participate in the next "BASIC10Liner" competition, in the following categories:

  • PUR-120 - A game in 10 lines of max 120 characters (w/abbrev.)
  • EXTREME-256 - A game in 10 lines of max 256 characters (w/abbrev.)
  • SCHAU - Any program in 10 lines of max 256 characters (w/abbrev.)
In order to reduce space you can use this abbreviation for this instruction:

CLEAR ↔ Clr

Any problem?

If you have found a problem with this keyword, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!

open an issue BACK TO KEYWORDS