Download presentation
Presentation is loading. Please wait.
1
Lists Alice
2
Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing the same marching steps. In such situations, it is convenient to collect all the objects into a group (a collection)
3
List One way to organize objects into a collection is to use a list.
In our daily lives, we use lists to help us organize things. For example, assignments list shopping list In programming, a list is known as a data structure.
4
Types of Lists In Alice, a list can be a list of numbers or a list of objects, colors, or other type …. In this session, we will use an example of a list of objects.
5
Example The famous Rockettes® are preparing for their winter holiday show. You have been hired to create an animation for the holiday show that will be used on a web site where people can purchase tickets for the show.
6
Creating a list: Step 1 Create the initial world and add five rockette objects to the world. Then, create a new world-level variable in the properties panel. (Why should it be world-level rather than class-level?)
7
Creating a list: Step 2 In the popup dialog box, type in a name
select Object type check “make a List” box click new item button 5 times to select each of the 5 rockettes, one at a time
8
Programming with a list
Now that a list has been created, how do we use the list in a program? One of the most useful operations with a list is to repeatedly perform some action with each item in the list. We call this iteration or "iterating through a list."
9
Iterating through a list
Iteration can be done in two ways: in order (one at a time) all together (simultaneously)
10
Example: Iteration in Order
A typical chorus line dance involves each dancer (one after the other) kicking up one leg. Possible storyboard: kickUpRightLeg Parameter: whichRockette Do in order Do together whichRockette right thigh turn back whichRockette right calf turn forward whichRockette right calf turn back For all dancers in order item_from_dancers kickUpRightLeg
11
Demo Ch09Lec1Rockette-V1 Concepts illustrated in this example
A method that defines an action to be performed by objects in a list is a world-level method (it involves more than one object). In this example, kickUpRightLeg The For all in order statement traverses the list, one list item at a time.
12
Demo Ch09Lec1Rockettes-V2 Concepts
The For all together statement executes the action for all list items simultaneously. The kickUpRightLeg method is still the same. All we did was call the method from within a For all together iterative loop.
13
Assignment Read Chapter 9 Section 1, Lists
14
Lab Chapter 9 Lecture 1 Lab
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.