The DIM
command is used to reserve a specific space in the computer's
memory to hold data that you will use during the execution of your program.
In particular, you can use DIM
for a single variable
Declaring variables explicitly makes your code more readable and understandable,
especially in longer programs. Specifying the data type prevents type errors
when your program runs. You can initialize a variable when you declare it,
giving it an initial value different by 0 (the ugBASIC default value).
Moreover, when you need to use a particular data type (e.g. FLOAT
for scientific calculations), it is advisable to explicitly declare the variable.
The scope of a variable declared with DIM
depend on the context in which
it is declared. It may be local to a procedure or global to the entire program.
It is always a good practice to declare all variables at the beginning of a
program or procedure to improve readability and maintainability of the code, and
ugBASIC gives you the OPTION EXPLICIT
directive to ensure that you use
only defined variables.
Note that ugBASIC language, as other BASIC dialect, do not need to use DIM
to
declare a variable. The data type and scope is inferred from the context in which
the variable is first used.
DIM name [AS type] [= v][,name [AS type] [= v][, ...]]
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:
DIM (variable) ↔ Di
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