View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default for loop with step increment of 0.1

To add to thos ecomments try this

Sub test()
Dim i As Single
For i = 1.5 To 2 Step 0.1
p = i + 0.1 2
Debug.Print i
Debug.Print p
Next i
End Sub

As you will note as soon as i = 1.9 then i + 0.1 is greater than 2 (True) so
it never executes.

Mike
"choi4u" wrote:

Running this code
Sub test()
For i = 1.5 To 2 Step 0.1
Debug.Print i
Next i
End Sub

gives this output
1.5
1.6
1.7
1.8
1.9 .

Why does the output not include 2.0?
and what do I have to do to make the output include 2.0?

Thanks in advance.