Member-only story
Arrays
Arrays are "lists" of related values. Each value in the array is typically of the same type and distinguished only by the position within the array. For instance, all of one test’s quiz scores could be held in an array with the name quiz_scores. The first student’s score would be located in the first "bucket" of the array, the second student’s score in the "second" bucket, etc.
Arrays
For general information on data types and arrays, see the topic on Data Types.
Arrays are used to store lists of related information. Your shopping list (type = string); for the names of the students in a class (type = string); for the grades for the first exam (type = numbers).
Note: Array variables should usually be named with "plural" words. For example: grades, students, words.
The following are a few interesting properties/terminologies used with arrays:
Index of an array
Arrays have a single name but many values. How do we define which particular value we are interested in? The answer is, we provide a numerical "index.".
An index into an array is a number that refers to which bucket we are presently interested in. Suppose we have the following 5 grades in an array: [ 100, 95, 99, 87, 90 ];
The 3rd value in the array is 99.
The idea of a list of related information is so pervasive, all languages have arrays in some form or another. Thus, the "semantics" of arrays is always the same. The "syntax" and "usage" of arrays vary. Below we contrast C, Matlab, and Actionscript.
MatlabThe C LanguageActionscript
Arrays are indexed starting at: ONE
Arrays can be declared with [], brackets grades = [99, 100, 50];
Arrays indexed using the syntax of: parentheses, grades(1) = 99…