For - Next
This lets you repeat something a fixed number of times.
This can be used when you know in advance how many times you want to loop.
Positive Increment
This example will loop 5 times.
The Step 1 is optional because the default is plus 1.
Appending the variable name after the Next statement is optional, but it should be included for completeness.
Negative Increment
Here is an example using a negative increment.
Decimal Increment
Here is an example using a decimal increment.
Nested Loops
You can nest loops inside one another.
The outside loops through 5 times and for each loop, the inside loops 3 times.
Nested Loops - Combined Next Statements
You can also combine Next statements onto one line, although this is not recommended.
Always use separate lines for your Next statements. It makes your code much easier to read.
Exit For
The Exit For statement lets you exit the loop early.
Important
Remember that the loop counter is just a normal variable and its value "could be" changed from inside the loop.
Always ensure that the loop variable is not changed from inside the For - Next loop.
Be aware that when a For - Next loop finishes the index variable will actually have incremented past the final value.
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext