Warning
You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
arrays [2019/04/07 22:24] – created neils | arrays [2019/06/27 07:42] – neils | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Arrays ====== | ====== Arrays ====== | ||
- | Arrays must be defined using the '' | + | Arrays must be defined using the '' |
The syntax to define array is the following (note the square brackets): | The syntax to define array is the following (note the square brackets): | ||
Line 23: | Line 23: | ||
end | end | ||
- | Arrays are not initialized, which means that if you read the value of an array member without previously assigning a value to it, you will get unexpected results. For example: | + | **'' |
dim a[10] | dim a[10] | ||
Line 29: | Line 29: | ||
rem ** this will print an undefined number ** | rem ** this will print an undefined number ** | ||
- | Important: there is no runtime array bounds checking! The programmer has to make sure that the array subscript returns a number that is within the bounds of the array. Otherwise the result will be undefined. | + | **Important |
+ | |||
+ | ===== Fast array lookup ===== | ||
+ | |||
+ | If the variable and index are both byte types, the compiler can take advantage of the processor' | ||
+ | |||
+ | For example: | ||
+ | |||
+ | dim arr![255] | ||
+ | fastindex! = 42 | ||
+ | slowindex = 42 | ||
+ | rem -- fast lookup | ||
+ | item! = arr![fastindex!] | ||
+ | rem -- slow lookup | ||
+ | item! = arr![slowindex] | ||
+ | |||
+ | ~~DISCUSSION~~ |