For Loops

Submitted by: 

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

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.