![]() | ![]() | |||||||||||||||
|
ArraysArrays are composite types that are lists of values of one type. Individual values are accessed by an index. The type of the index can be either numeric or an enumerated type. Arrays are a fixed size and the size is determined by the a range of values for the index. The lower bound and upper bound of the array are set when the type is declared (or, in the case of an anonymous array, when it is used in a declaration). It is an error to access elements outside of the index's range. The built-in arrays package contains basic array subprograms. Anonymous ArraysTo declare an anonymous array (an array with no type name): => zerbra_population : array(1900..2009) of natural The first array contains 100 entries and each entry is a natural number. To assign values or to access array entries, put the index number in parentheses after the array name. => zebra_population(1950) := 150000 Attempting to use an out-of-range index number is an error. => ? zebra_population( 0 ) Array TypesYou can create new array types. => type zebra_list is array( 1900..2009 ) of natural; Initial ValuesWhen you declare an array, you can assign a list of initial values or copy the values of another identical array. When providing initial value, provide a value for each component in the array. => type grocery_list is array(1..10) of string => gl : grocery_list := ( "milk", "bananas", "bread", "butter",
"salt", "flour", "pizza", "noodles", "", "" ) Empty ArraysAn empty array can be created using 1..0. This is the only case where the low bound is higher than the high bound. => empty : array(1..0) of integer SparForte does not support assigning one array to another in an assignment statement, unconstrained arrays or multi-dimensional arrays. Ada: SparForte does not (yet) implement arrays with multiple dimensions (arrays of arrays). Character and indefinite indexes are not implemented. Arrays cannot contain records. others is not yet implemented for assignment. |
![]() Block Statements and Subprograms |
![]() |
![]() |