Dim answer As Integer
Dim startNumber As Integer
Dim startNumber As Integer
answer = 0
For startNumber = 1 To 4
answer = answer + startNumber
Next startNumber
For startNumber = 1 To 4
answer = answer + startNumber
Next startNumber
MsgBox(answer)
What this will do is add the numbers 1 to 4, without having to write 1+2+3+4, i mean those few numbers aren't gonna take long to write down, but what about 100 numbers?
It's basicly saying answer(0) plus startnumber(1) and making the result answer(1), so next loop is answer(1) plus startnumber(2) = answer(3) and so forth! :D
Next
For intCount As Integer = 4 To 62 Step 7
listbox.items.add(intCount)
Next
Now what does the step 7 do?
First we see what the loop does without the step 7.
It takes the numbers from 4 to 62 and lists them in the listbox,
now with the step 7, it only takes every seventh number and adds
to the listbox, so instead of going 4, 5, 6 and so forth it goes,
4, 11, 18 and so forth.
Next
For intCount As Integer = 4 To 62 Step 7
listbox.items.add(intCount)
Next
Now what does the step 7 do?
First we see what the loop does without the step 7.
It takes the numbers from 4 to 62 and lists them in the listbox,
now with the step 7, it only takes every seventh number and adds
to the listbox, so instead of going 4, 5, 6 and so forth it goes,
4, 11, 18 and so forth.
For intCount As Integer = 4 To 62 Step 7
listbox.items.add(intCount)
if intcount = 18 then
exit for
end if
Next
Now as you can see, i added an If statement, and what i told it do,
is if intcount is 18 then it must run the command "Exit For",
which very simply, exits the loop and stops at 18.
is if intcount is 18 then it must run the command "Exit For",
which very simply, exits the loop and stops at 18.
-Rasmus Iversen
No comments:
Post a Comment