PDE - Creating an Array / List (Lesson)
How is a List Created as an Array in Code?
An array is a place to hold data of like data type all in one place to be used separately or together in some fashion. Consider your classrooms that you are in. Each teacher has a specific list of students, specifically for their class. A smaller list of objects, than the list of for the overall school. Teachers access this list of students, but not all of the students in the school.
Given a list of numbers below, how would a array of data be created?
2, 5, 16, 19 , 24
Basic Array Creation and Reading the Array
- The variable box will pop up and you will select wholeNumber for this list.
- Next to the whole Number selection is a box with array next to it. Click in the array box to turn on the option.
- Name your list nbrList or any other appropriate name that you want.
- Last you will need to initialize the list. You could initialize the list to all 0's and add this information later or include the information now.
See the basic video of creating an array below. The first is for an object array, the second video is for the number array.
Note:
- Each array data structure is written in set notation for it's construction, therefore this type of statement is called a constructor.
- The braces around the numbers.
Creating an Array of Number
Below is a video creation of an array of numbers.
Notes
The first video had to chose the objects while creating the array data structure. These cannot be chosen later. Therefore the object must be currently in your scene and available for choosing.
The second video created an array using the default data structure and demonstrated using a say statement to output the data.
IMAGE CREATED BY GAVS AND USED ACCORDING TO TERMS OF USE.