Range iterates over elements in a variety of built-in data structures. Let’s see how to use For Each with some of the data structures we’ve already learned.
Here we use For Each to sum the numbers in an array. Arrays work like this too.
For Each on arrays and collections provides both the index and value for each entry. In the above example, we didn’t need the index, so we ignored it. Sometimes we actually want the indexes though.
For Each on dictionary iterates over key/value pairs.
For Each can also iterate over just the keys of a dictionary.
For Each on strings iterates over Unicode code points. The first value is the character itself. See Strings and Runes for more details.
To run the programs, compile the VB.NET code using vbc and execute it.