13.07.2015 Views

Turbo Basic

Turbo Basic

Turbo Basic

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

DIM statementFunctionSyntaxRemarksDIM declares arrays.DIM {STATICIDYNAMIC} var (subscripts) [,var(subscripts)] .••DIM {STATIC I DYNAMIC} var (min:max [,min:max] ..• )[,var [,min:max]] ..•var is an identifier used for the array.subscripts is a comma-delimited list of one or more integerexpressions defining the dimensions of the array.DIM declares array variables and defines their size and numberof dimensions.In an enhancement to Interpretive BASIC syntax, <strong>Turbo</strong> <strong>Basic</strong>allows you to define a range of subscript values (min:max) ratherthan just an upper limit. For example:DIM b(50:60)creates an array of 11 single-precision elements, numbered 50through 60. The statementDIM c(50:60, 25:45)creates a two-dimensional array of 11 X 21 total elements.The range syntax can be extended for multidimensional arrays:DIM births(1800:1899,1:12)The related OPTION BASE statement can also be used to determinethe lowest element in an array, although the range mechanismis more powerful and is preferred.<strong>Turbo</strong> <strong>Basic</strong> sets each element of a numeric array to 0 when aprogram is first executed, and sets string arrays to the null string(length = 0). If a program is restarted again with the RUN statement,numeric arrays are reset to 0 and string arrays to the nullstring.If an array variable is used without a preceding DIM statement,the maximum value of its subscripts defaults to 10, as though youhad included (10) in your DIM statement. It is good practice, however,to explicitly declare every array.The minimum value that can be used as an array subscript is 0,unless specified otherwise with the OPTION BASE command.The optional STATIC and DYNAMIC arguments control, respectively,whether space for the array will be pre-allocated by the compileror allocated dynamically. If omitted, arrays default to static<strong>Turbo</strong> <strong>Basic</strong> Reference Directory 185

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!