A For loop iterates a certain number of times, the value of the counter variable changing each iteration. The For loop is the most well-known looping statement and useful in many programs. A For loop looks like this this:

Fora=1To10' Loop code hereNext

will loop 10 times, since on the first iteration, a would equal 1, the second iteration 2, etc.

A For loop such as this one:

Fora=10To1Step-1' Loop code hereNext

will loop 10 times, but the counter starts at 10 and goes down to 1.

A For loop like this one:

Fora=11To20' Loop code hereNext

will also loop 10 times. The counter would start at 11 then stops when it reaches 20 .

A For Each loop iterates over every index of an array or other iterable object. It requires an object to iterate through, and a variable to hold an index's contents. The object to iterate must implement the IEnumerable or IEnumerator interfaces. The implementation of IList by Array allows arrays to be used as an object, because IList inherits from IEnumerable.

Sample:

DimarrAsInteger()={1,2,3}DimiAsIntegerForEachiInarr' During each iteration of the For Each loop, i will assume one of three values:' 1, 2, or 3 as integers.Nexti