BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"True Array size and index"
, by thechange
When creating an array, it contains the specified number of elements plus an *additional* element.
Code
; When you create an array like this: Dim Array( 10 ) ; It does not contain 10 numbers, but in fact, 11! ; Because the first number has an index of 0 and the last has an index of 10. ; Like this: For i = 0 to 10 Print Array( i ) Next ; The same goes for BlitzArrays, inside and outside a Type collection. ; Simple BlitzArrays: Local BlitzArray[ 7 ] For i = 0 to 7 BlitzArray[ i ] = i Next ; And Arrays inside Types: Type ArrayType Field FieldArray[ 9 ] End Type Local Instance.ArrayType = New ArrayType For Counter = 0 to 9 Instance\FieldArray[ Counter ] = Rnd( -2147483648 , 2147483647 ) Next Delete Instance ; Usually it doesn't matter if you omit the first record (index 0) of an array ; But it can also speed up your program if you do :) ; For example: Const Total = 250 Dim Records( Total ) For Record = 1 to Total Records( Record ) = Rnd( -1 , 1 ) Next ; Comparing the above to a zero-based example: Const Total = 250 Dim Records( Total-1 ) For Records = 0 to Total-1 Records( Record ) = Rnd( -1 , 1 ) Next ; Have fun :D
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations