I need a For Next loop that will calculate and display the square of the even numbers from 2 to 12.
kazooie21
Printable View
I need a For Next loop that will calculate and display the square of the even numbers from 2 to 12.
kazooie21
Dim i as Integer
for i = 2 to 12
If i Mod 2 = 0 then
Debug.print i & " " & Sqr(i)
End If
next i
Since Mod is a relatively slow process I would use the step option instead of mod'ing each iteration.
Dim i as Integer
for i = 2 to 12 step 2
Debug.print i & " " & Sqr(i)
next i
Brewguru99
although I doubt that speed is a major concern in this case :-)
, I think you solution is more elegant.