Creating an Array: Difference between revisions

Content added Content deleted
(Task description: initialize array with data.)
(→‎{{header|BASIC}}: Dimension given is the upper bound.)
Line 169: Line 169:
{{works with|PB|7.1}}
{{works with|PB|7.1}}


The default array base can be set with OPTION BASE. If OPTION BASE is not set, the base may be either 0 or 1, depending on the implementation.
The default array base (lower bound) can be set with OPTION BASE. If OPTION BASE is not set, the base may be either 0 or 1, depending on implementation. The value given in DIM statement is the upper bound. If the base is 0, then DIM a(100) will create an array containing 101 elements.
<lang qbasic> OPTION BASE 1
<lang qbasic> OPTION BASE 1
DIM myArray(100) AS INTEGER </lang>
DIM myArray(100) AS INTEGER </lang>


Alternatively, the low and high bounds can be given while defining the array:
Alternatively, the lower and upper bounds can be given while defining the array:
<lang qbasic> DIM myArray(-10 TO 10) AS INTEGER </lang>
<lang qbasic> DIM myArray(-10 TO 10) AS INTEGER </lang>