In most cases, you control the number of iterations with a variable used as a counter, which typically increments until a certain target number is reached. However, you can also loop through a set of data until you reach the end of the set. The three main types of loops that you can use are For..Next, For Each..Next, and Do Loops. There are other types of loops, such as the While..Wend, but these are the three main ones that you should be using.
The For..Next
For…Next loops are used when you want to execute a block of code a specific number of times. The For statement specifies the counter variable and its start and end values. The Next statement increases the counter variable by one. You can use the Step keyword to increase or decrease the counter variable by the value you specify. This value can be either positive or negative.
The For Each..Next Loop
The For Each..Next loop repeats a block of code for each item in a collection, or for each element of an array.
The Do Loop
You can use the Do..Loop when you need to repeat a block of code, but you do not know how many repetitions are needed. The statements are repeated either while a condition is TRUE or until a condition becomes TRUE.
The Exit Keyword
You can also always exit a loop block by using the Exit keyword. The Exit keyword simply alters the flow of control by causing an exit from a repetitive cycle. You can use the Exit keyword in various situations, such as when avoiding an endless loop.