Chapter 10. Arrays

When you store data, such as numbers or strings, in a variable, you can store only one chunk of data at a time. If you need to store five different numbers, you have to create five different variables. If you need to store 100 different numbers, you have to create 100 different variables. Clearly, having to create a new variable to store each new chunk of data is clumsy and inefficient, so programming languages offer a solution called an array.

An array essentially acts like a single variable that can store multiple chunks of data. Rather than acting like an individual box that can hold only one chunk of data, such as a single variable, an array acts like a big box divided into sections, where each section can store one chunk ...

Get Mac Programming for Absolute Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.