# CS Revision – Arrays

Arrays are list of similar items, usually used in loops and repetitions. They contain similar items. The items in the list are the elements of the array.

One-dimensional array are lists identified by the use of a single name and each item int eh list can be found by an index number showing the place in the list.

What to consider when using a one-dimensional array:

• name of the array depending on its uses
• size depending on the number of elements in the array
• datatype depending on the type of element stored (names, ages, address, etc)

Example of arrays syntax in pseudocode:

DECLARE teachernames: ARRAY[0:2] of String
teachernames[0] <--- "Mr. Li"
teachernames[1] <--- "Ms. Lloyd"
teachernames[2] <--- "Mrs. Fox"
FOR i 0 TO 2
OUTPUT teachernames[i]
NEXT

So generally, DECLARE arrayname: ARRAY[0:arraylength] of datatype.

The concept of parallel arrays is very convenient to use in problem solving. Parallel arrays have the same sizes and use the same variable for their indexes.

Going through an array item by item is called traversing the array.

Up Next:

#### Vanuatu · Stranded

Vanuatu · Stranded