Dim num as Integer
For num = 1 To 5 Step -1
MsgBox num
Next num
Isn't the loop above suppose to run at least once?
Printable View
Dim num as Integer
For num = 1 To 5 Step -1
MsgBox num
Next num
Isn't the loop above suppose to run at least once?
nope.
Dim num as Integer
For num = 1 To 5 Step +1
MsgBox num
Next num
would make it run, or 5 to 1 step -1
but not like that
Private Sub Form_Load()
Dim num As Integer
For num = 1 To 1 Step -1
MsgBox num
Next num
End Sub
will run once
i remembered that in C this code will run at least once
Is this because cause 'Step' is just that, it will "step" through the loop and the + or - tells it what direction to go ?
Quote:
Originally Posted by newace
In C that will be an endless loop. Why it isn't that in VB...hmmm...no idea..:D
vb is *smarter* than C++
Quote:
Originally Posted by dglienna
That is nearly a post to get banned for..:)
Well I guess it is true some how. It at least saves you a Ctr+Alt+Del thats for sure.
ØØ
but how come the following runs?
For num = 1 To 1 Step -1
MsgBox num
Next num
End Sub
because it isn't false until it cycles through the first time. as soon as it applies the step value it is false.
Step has two purposes, to Increment/Decrement the counter value and determine loop processing. The rule is
If Step is Positive or 0 then Counter Value must be <= End Value
If Step is Negative then Counter Value must be >= End Value
Its all in the help file.