View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis[_3_] Dana DeLouis[_3_] is offline
external usenet poster
 
Posts: 690
Default Why this basic LOOP does not work!

Here's an example where the loop counter is set outside the range. The
"For" loop code still needs to run its test.
5.5 is incremented by 1 to 6.5. The test now fails, and the code
continues...

Sub Demo()
Dim j
For j = 1 To 3
Debug.Print j
j = 5.5
Debug.Print j
Next j
Debug.Print j
End Sub

1
5.5
6.5

--
Dana DeLouis
Win XP & Office 2003


"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.