Arrays

Introduction
An [|array] is a variable which holds multiple values of the same type.

Consider a situation where we want to store the maximum temperature every day of the week. Using individual variables, we would end up with the following:

This would mean 7 different variables, one for each day of the week. And what would happen if we wanted to extend the program to store temperatures for every day in the month, or even the year? That's a lot of variables!

Instead, we can store the temperatures in just one variable, an array: In this array we have 7 elements - one for each day of the week. We can then assign values to individual elements of the array as follows:



It is very important to note that we reference items in the array starting from 0, not 1. So the first item in our array is DailyTemp(0), and the last item in our array is DailyTemp(6).

It is also possible to assign values to **all** elements in the array, as follows:

We can access any element in the array as follows:



Arrays are often used in conjunction with loops. It's simple to loop through an array and process the data within it. In the example below, the program loops through the daily temperatures in order to calculate the average.



**Tutorial**
[|Top Ten]

**Tutorial**
[|Months]

Task 1
Team Member

Task 2
Reality TV Votes