Skip to content
aanon4 edited this page Oct 22, 2014 · 2 revisions

Syntax

<variable> = <expression>
DIM <variable>(<expression>)
<variable>(<expression>) = <expression>
<variable> = <expression>,<expression>,...

Description

Blue Basic defines 26 variables, "A" to "Z". These variables are globally shared by all code in the program. Each holds a 32-bit, signed integer value, initially set to zero.

Variables can be used in exactly the same way as a literal number. For example:

PRINT 0
PRINT A

The first prints the number "0" to the console. The second also prints "0" to the console (assuming you have not run any code yet).

Variables can be assigned any integer value using the "=" operator:

A = 10
B = 2 * A

Arrays

Blue Basic also supports arrays. An array overrides the use of an integer variable and, instead, lets the variable be used to store an index set of values. For arrays, each element can hold an unsigned 8-bit value. In the following:

DIM A(10)

An array named "A" is defined to hold 10 byte elements. These have indexes between 0 and 9. Each element is accessed using its index, written in parenthesis after the array name.

PRINT A(0)
PRINT A(9)
PRINT A(1) + A(2)
PRINT A(B + 1)

Arrays can be assigned to in two ways; either as a whole or as individual elements. For example:

A = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

This assigns the 10 values to the ten elements in the array. Alternatively we can just assign a single element:

A(2) = 3

Unlike integer variables, arrays are not global. Arrays only exist after the "DIM" definition is executed. If this happens in a subroutine (see GOSUB), the array will only exist for the duration of the subroutine.