Why this basic LOOP does not work!
What confuses me is that loop says "i" would get the maximum value of 3
and
the loop would end with this value.
Actually what happens is the loop continues until i exceeds the max. At the
start of the fourth For i is incremented and compared to the max of three.
--
Jim
"GreenInIowa" wrote in message
...
| Chip,
|
| What confuses me is that loop says "i" would get the maximum value of 3
and
| the loop would end with this value. In fact, as soon as it reaches 3 it is
| "out" of the loop and continues with the next step. But at what step it
| increments again?
|
| I know you are right, but it is not making much of a sense to me.
|
| Thanks.
|
| "Chip Pearson" wrote:
|
| The loop control variable is incremented in the For statement.
| Thus For is called 4 times, not 3, and the value 4 fails the
| test, and control is moved to the line of code following the Next
| statement.
|
|
| "GreenInIowa" wrote in
| message
| ...
| Hi,
|
| I have the following simple loop where I want "i' to go from 1
| to 3.
|
| Sub test()
| For i = 1 To 3
| Debug.Print "Inside of the loop"; i
| Next
| Debug.Print "Outside of the loop"; i
| End Sub
|
|
| ==Out put is ==
| Inside of the loop 1
| Inside of the loop 2
| Inside of the loop 3
| Outside of the loop 4
|
|
| It does what I expect inside the loop. But, as soon as loop is
| completed its
| value increases by one to 4 although I see no reason for this.
| Why? Anybody
| has any answer for this?
|
| Thanks.
|
|
|
|