Repeating commands with a For...Next loop

If you want to repeat commands a set number of time, use a For...Next loop. For example:

For i = 1 to 10

If i < 9 Then 

MsgBox "Reminder " & i 

Else 

MsgBox "Reminder " & i & ", almost there" 

End If 

Next

VBScript starts by setting a variable i to 1 and then executing the commands sandwiched between the For and Next statements. Because i can be referenced within this block, the first time the block is executed, the message box will display:

"Reminder 1"

When the Next line is reached, VBScript adds one to i and returns execution to the top of the block. And this process is repeated until i reaches 10. So the last message to be displayed is:

"Reminder 10, almost there"