Originally posted by dongaman
Run below codes
Code:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Command1_Click()
Dim i, j, k, temp, ret1, ret2, ret3 As Long
k = 1000000
''''''''''''''''''''
j = GetTickCount()
For i = 1 To k
temp = 3
Next
'MsgBox "For/Next:" & GetTickCount() - j
ret1 = GetTickCount() - j
''''''''''''''''''''
i = 1
j = GetTickCount()
Do While i <= k
temp = 3
i = i + 1
Loop
'MsgBox "Do/Loop:" & GetTickCount() - j
ret2 = GetTickCount() - j
'''''''''''''''''''''
i = 1
j = GetTickCount()
While i <= k
temp = 3
i = i + 1
Wend
ret3 = GetTickCount() - j
MsgBox "For/Next:" & ret1 & vbCrLf & "Do/Loop:" & ret2 & vbCrLf & "While/Wend:" & ret3
End Sub
To be sure that returned values are correct you need to do the same actions in them loops.
Therefore the results are incorrect cause in the For/Next loop you're doing much less then in others.

Add a extra long to it t As long
Add a line in the for next loop t = t +1
and your results will be more correct.