For Loops
Submitted by Yorkiebar on Sunday, October 20, 2013 - 01:59.
What is a For Loop?
A For Loop is used to iterate through a script a certain amount of times. Personally, I use it to check conditions for each item within a group, list or array.
How do I use a For Loop?
To create a For Loop you first need to decide how many times you want a script to run. You also want to create a script which will be ran.
Once you have decided on both of those options you will want to set it out in the following format:
Now we need to swap the parts surrounded by {} with the real programming. The following script uses the variable as 'i' because 'i' is a convention in programming as a variable name that doesn't server any major purpose.
The script will output the value of 'i' (which will increase by one for each loop) in a messagebox each time it loops...
So the above script outputs the numbers 0 to 10 (11 different messageboxes). We can do the same thing but using variables just as easily...
- For {variableName} As Integer = {start} To {end}
- Next
- For i As Integer = 0 To 10
- MsgBox(i)
- Next
- Dim start As Integer = 0
- Dim endPosition As Integer = 10
- Dim output As String = "Message"
- For i As Integer = start To endPosition
- MsgBox(output)
- Next
Add new comment
- 188 views