-
Solved: Question About For Loop Execution
Given a FOR loop similar to the following:
[VBA]For N=1 to 7 * XXX
Cnt = Cnt + 1
Next N[/VBA]
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?
-
This little code snippet says that you cannot change the limit:
[vba] 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
[/vba]
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.
-
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules