Alice Programming
Learn Alice in FREE step-by-step lessons.
Module 17: Arrays: Working with lists of objects
An array is a list. When you declare an array in Alice, you can select to make it an array.
The variable greeting is not an array, it is a scalar. It has a single value, "Hello World".
When the tortoise says greeting, he says "Hello World"
The variable sayings is an array. The items in an array are numbered starting with 0. The number is called the index or subscript. When you use an array you need to use a subscript to specify which item, or element, in the list is to be used.
In this example, the tortoise says sayings[0], of "Ready".
An array can also use variables as the subscript:
In this example, num is 1, so when the tortoise says sayings[num] he says "Set".
In this module, you will declare and use arrays. An array is a variable that is a list.
You will create arrays of words, numbers, or objects, then use loops to process the entire array.
Goal:
- Learn to declare and use arrays (lists)
- Understand how arrays can act on groups of objects together
- Learn to create array of different types, including objects.
- Use the control structures that operate on arrays
- Define parallel arrays and name ways to use them
- Be able to use arrays of segments
In order to do this you will:
Objectives:
- Declare a variable to be an array.
- Create code to assign initial values to an array.
- Use subscripts or index to access the elements of the array.
- Utilize loop control structures to process all of the elements of the array.
- Create and process arrays of different data types, including arrays of objects.
- Understand the purpose of parallel arrays and ways to use them.
- Experiment with arrays of segments, such as the segments of an elephant's trunk or tail.