• We just launched and are currently in beta. Join us as we build and grow the community.

For Loops

Viktor123098

Codebase Quality Auditor
V Rep
0
0
0
Rep
0
V Vouches
0
0
0
Vouches
0
Posts
48
Likes
32
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
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

Book traversal links for For Loops

  • ‹ File Handling: Writing and Saving a Text File
  • Up
  • For each Loop ›

 

452,292

323,891

323,899

Top