Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Arrays

1,458 views

Published on

  • Be the first to comment

Arrays

  1. 1. ARRAYSA WHOLE HEAP OF BUCKETS
  2. 2. One Variable Can Only Hold One ThingI’m holding the name DAVE Name
  3. 3. One Variable Can Only Hold One Thing DON’T TRYI’m holding AND PUT the name ANOTHER DAVE NAME IN Name ME!
  4. 4. An Array is Different kind of VariableI’m holding I’m holding I’m holding the name the name the name DAVE ADAM CLEM 0 1 2 Name
  5. 5. An Array is Different kind of VariableAn array is a set of values that are logically related to each other, such as the number of students in each grade in a grammar school. 0 1 2 Name
  6. 6. An Array is Different kind of VariableAn array is like many buckets stuck together 0 1 2 Name
  7. 7. An Array is Different kind of Variable An Array has many compartments to hold dataThe array below has 3 compartments. It can hold 3 pieces of data 0 1 2 Name
  8. 8. An Array is Different Each compartment is labelled The labelling starts from 0Index 0 Index 1 Index 2 0 1 2 Name
  9. 9. An Array is Different You can access different parts of the array by referencing the correct index numberIndex 0 Index 1 Index 2 0 1 2 Name
  10. 10. Arrays In VB Declaring the Declaring the Declaring the data type of the Array size of the Array Array, in this case a String Dim names(3) As String names(0) = "DAVE" Declaring thecontents of the names(1) = "ADAM" Array names(2) = "CLEM"
  11. 11. Arrays In VBDim names(3) As String names(0) = "DAVE" names(1) = "ADAM" names(2) = "CLEM" Console.WriteLine(names(0)) Console.WriteLine(names(1)) Console.WriteLine(names(2)) Writing the contents of the Console.ReadLine() array to the console.
  12. 12. Arrays In VBDim names(3) As String names(0) = "DAVE" names(1) = "ADAM" names(2) = "CLEM" Console.WriteLine(names(0)) Console.WriteLine(names(1)) Console.WriteLine(names(2)) Console.ReadLine() Erasing the contents of theErase names Array
  13. 13. Arrays and WHILEModule Module1 The while loop will Sub Main() look at every Dim names(3) As String compartment of names(0) = "DAVE" the names array names(1) = "ADAM" names(2) = "CLEM" Dim i As Integer = 0 While i < names.Length - 1 Console.WriteLine(names(i)) i = i + 1 End While Console.ReadLine() End Sub
  14. 14. Arrays and WHILEModule Module1 Sub Main() Dim names(3) As String names(0) = "DAVE" names(1) = "ADAM" names(2) = "CLEM" Dim i As Integer = 0 While i < names.Length Console.WriteLine(names(i)) i = i + 1 End While Console.ReadLine() End Sub

×