50
Programming with TIDE
©2000-2008 Tibbo Technology Inc.
On seeing ".0" at the end of the value compiler will realize that the value must be
treated as a real one (floating-point format) and process the value correctly.
So, why is it possible for compiler to automatically process values that fit into 8,
16, and 32 bits, but at the same time requires your conscious effort to specify that
the value needs to be treated as a floating-point one?
This is because floating-point calculations are imprecise. The value
"12345678901", when converted into a floating-point format, will not be exactly
the same! The floating-point value will only approximate the value we intended to
have!
For this reason we require you, the programmer, to make a conscious choice when
specifying such values. By adding ".0" you acknowledge that you understand
potential imprecision of the result.
4.2.4.5
Arrays
An array is a single variable which contains several elements of the same type.
Each element has a value and an index number, and may be accessed using this
number.
An example of a simple array would be:
Index:
0
1
2
3
4
Value:
15
32
4
100
-30
The code to produce such an array in Tibbo Basic would look like this:
dim
x(
5
)
as
char
x(
0
) =
15
x(
1
) =
32
x(
2
) =
4
x(
3
) =
100
x(
4
) = -
30
The first index in an array is 0. Thus, the array above contains 5 values, with
indices from 0 to 4.
This is different from some BASIC implementations that understand x
(5) as "array x with the maximum element number of 5" (that is, with
6 elements). In Tibbo Basic declaring x(5) means "array of 5 elements,
with indices from 0 to 4".
Variable Types For Arrays
In the example above, the array was assigned the type char. This means that each
element within this array will be stored in a variable of type
. Starting
from Tibbo Basic
V2.0
you can have arrays of variables of any type.
Accessing a Value Within an Array
To access a specific value within an array, include its index immediately after the
name of the array, in parentheses. The index may also be expressed through a
43