For Loops

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:
  1. For {variableName} As Integer = {start} To {end}
  2. Next
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...
  1. For i As Integer = 0 To 10
  2. MsgBox(i)
  3. Next
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...
  1. Dim start As Integer = 0
  2. Dim endPosition As Integer = 10
  3. Dim output As String = "Message"
  4. For i As Integer = start To endPosition
  5. MsgBox(output)
  6. Next

Add new comment