ForEachLoops

Iterating Through Array Elements

Private Sub btnIterate_Click(sender As System.Object, _
        e As System.EventArgsHandles btnIterate.Click
 
       
        Dim result As New System.Text.StringBuilder
        Dim fruitArray() As String = { _
           "Oranges""Apples""Grapes""Bananas""Blueberries"}
 
        For Each fruit As String In fruitArray
            result.AppendLine(fruit & ", ")
        Next fruit
 
 
        'The following codes creates a simple string array of 
        'fruit names, then processes each string in the array 
        'inside a For Each loop:
        ListBox1.Items.Add("")
        ListBox1.Items.Add("Example I: Using a String.Builder" & _
                           "to create a single string object" & _
                           "combining all elements the array.")
        ListBox1.Items.Add(result.ToString())
 
 
        ListBox1.Items.Add("")
        ListBox1.Items.Add("Example II: Simple Iteration showing individual array elements.")
        For Each item As String In fruitArray
            ListBox1.Items.Add(vbTab & item)
        Next
 
    End Sub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: