View Full Version : Solved: Question About For Loop Execution

10-05-2005, 08:31 PM
Given a FOR loop similar to the following:
For N=1 to 7 * XXX
Cnt = Cnt + 1
Next N

I know that N can change or be changed while the loop is executing. But what about the limit value (7*XXX, in this case)? If XXX changes during execution, does that change the limit?

10-05-2005, 10:47 PM
This little code snippet says that you cannot change the limit:
Dim xx As Integer, i As Integer

xx = 5

For n = 1 To xx
If n < 3 Then xx = xx + 1
MsgBox "n: " & n & "; xx: " & xx
Next n

This is actually a surprise to me. I knew that VBA performs the limit test on each cycle, but apparently it sets the limit as a constant on initiating the loop.

10-06-2005, 04:29 PM
Hey, Blue, thanx for the reply. I've wondered about that off and on for some time now. I can take advantage of that now. :beerchug: