Don’t use a for next loop if you are not utilizing the iteration object.

A brief summary of what this means is that if you are using a for-next loop, you would only want to use the object that is iterated. You could call a for-next loop an object iteration loop. Where-as a Do-While loop is a condition-iteration loop.

Object Iteration Loop:
In the following loop, a collection(list of string) is iterated.

        Dim items As New List(Of String) From {"a", "b", "c"}
        For Each item As String In items
            MsgBox(item) '<-- utilizing the iteration object
        Next

Condition Iteration Loop:
In the following loop, a collection is not iterated through, instead a value is modified, and the loop ends when a certain condition becomes true.

        Dim i As Integer = 0
        Do
            i += 1
        Loop Until i = 100 '<-- evaluating a condition
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