Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional.

Similar presentations


Presentation on theme: "Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional."— Presentation transcript:

1 Arrays-Part 1

2 Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional array Code a loop using the For Each…Next statement Access an element in a one-dimensional array

3 Using Arrays Simple variable (or scalar variable): a variable that is unrelated to any other variable in memory Array: –A group of variables with the same name and data type that are related in some way –Used to temporarily store related data in memory –Increases the efficiency of a program Commonly used arrays: –One-dimensional –Two-dimensional

4 One-Dimensional Arrays One-dimensional array: –Can be viewed as a column of variables Subscript: –A unique number that identifies each variable in a one-dimensional array –Starts at 0 for first element in the array Use array name and subscript to refer to each individual variable in the array

5 One-Dimensional Arrays (continued) Syntax: [dim | Private] arrayname(highestsubscript) As datatype Or [dim | Private] arrayname() As datatype =[initialvalues] Element: an individual variable in the array When an array is declared: –Each element in the array is initialized if no values are provided –Initial values can be specified for elements

6 Storing Data in a One-Dimensional Array Example: –In class Hands-on

7 Manipulating One-Dimensional Arrays Array elements can be used like any other variable Examples: –Display the contents of an array –Access an array element using its subscript –Search the array –Calculate the average of data stored in a numeric array –Find the highest value stored in an array –Update array elements –Sort array elements

8 Displaying the Contents of a One-Dimensional Array Example In class Hands-on

9 The For Each…Next Statement For Each…Next statement: –Used to code a loop which processes each element in a group or array –Creates a variable used to represent each item in the group or array –Data type of the element must match the data type of the group –Syntax: For Each element [As datatype] in group [Statements] Next elements

10 Summary Arrays: a group of related variables with the same name and same data type Array element: one item in the array One-dimensional array: each element is uniquely identified by its position (subscript) in the array Two-dimensional array: each element is uniquely identified by its position (row and column subscripts) in the array Subscripts are zero-relative Number of elements in an array is the highest subscript value + 1 For Each...Next statement: used to loop through all the elements in an array


Download ppt "Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional."

Similar presentations


Ads by Google