Page 235 - Learn To Program With Scratch
P. 235

9


















                                                      L i S t S












                          The programs we’ve written so far have used ordinary

                          variables to store single pieces of data. Such variables
                          are not as useful, however, when you want to store a
                          bunch of values, such as your friends’ phone numbers,
                          names of books, or a month of temperature readings.

                          For example, if you wanted your program to remember the phone numbers
                          of 20 of your friends, you’d need 20 variables! Certainly, writing and main-
                          taining a program with 20 variables would be tedious. In this chapter, we’ll
                          explore another built-in data type, called a list, which offers a convenient
                          way to group related values. Here’s what we’ll cover:
                          •   How to create and manipulate lists
                          •   Initializing and accessing individual elements in a list
                          •   Basic sorting and search techniques
                          •   Using lists to create powerful applications

                             First, I’ll explain how to make lists in Scratch, demonstrate the com-
                          mands you can use with them, and show you how to populate lists with data




                                           www.it-ebooks.info
   230   231   232   233   234   235   236   237   238   239   240