際際滷

際際滷Share a Scribd company logo
ARRAYS
A WHOLE HEAP OF BUCKETS
One Variable Can Only Hold One
               Thing



Im holding
 the name
   DAVE
               Name
One Variable Can Only Hold One
               Thing


                          DONT TRY
Im holding                AND PUT
 the name                 ANOTHER
   DAVE                    NAME IN
               Name          ME!
An Array is Different kind of Variable

Im holding   Im holding   Im holding
 the name      the name      the name
   DAVE          ADAM          CLEM



      0             1           2

                Name
An Array is Different kind of Variable
An 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
An Array is Different kind of Variable

An array is like many buckets stuck together




      0              1              2

                 Name
An Array is Different kind of Variable
     An Array has many compartments to hold data

The array below has 3 compartments. It can hold 3 pieces
                        of data




       0                   1                   2

                      Name
An Array is Different
               Each compartment is labelled

                The labelling starts from 0


Index 0             Index 1             Index 2




          0                   1                   2

                        Name
An Array is Different
  You can access different parts of the array by referencing
                 the correct index number



Index 0              Index 1             Index 2




          0                    1                   2

                         Name
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 the
contents of the names(1) = "ADAM"
    Array
                names(2) = "CLEM"
Arrays In VB
Dim 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.
Arrays In VB
Dim 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 the
Erase names
                                        Array
Arrays and WHILE
Module 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
Arrays and WHILE
Module 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

More Related Content

Arrays

  • 1. ARRAYS A WHOLE HEAP OF BUCKETS
  • 2. One Variable Can Only Hold One Thing Im holding the name DAVE Name
  • 3. One Variable Can Only Hold One Thing DONT TRY Im holding AND PUT the name ANOTHER DAVE NAME IN Name ME!
  • 4. An Array is Different kind of Variable Im holding Im holding Im holding the name the name the name DAVE ADAM CLEM 0 1 2 Name
  • 5. An Array is Different kind of Variable An 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. An Array is Different kind of Variable An array is like many buckets stuck together 0 1 2 Name
  • 7. An Array is Different kind of Variable An Array has many compartments to hold data The array below has 3 compartments. It can hold 3 pieces of data 0 1 2 Name
  • 8. An Array is Different Each compartment is labelled The labelling starts from 0 Index 0 Index 1 Index 2 0 1 2 Name
  • 9. An Array is Different You can access different parts of the array by referencing the correct index number Index 0 Index 1 Index 2 0 1 2 Name
  • 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 the contents of the names(1) = "ADAM" Array names(2) = "CLEM"
  • 11. Arrays In VB Dim 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. Arrays In VB Dim 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 the Erase names Array
  • 13. Arrays and WHILE Module 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. Arrays and WHILE Module 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