Executing VBScript Loops

If you want to repeat an action more than one time, VBScript provides a variety of constructs for doing so. The first, called a For...Next loop, executes a set of statements some number of times. You specify three expressions: an initial expression, which sets the values of any variables that you need to use; a final value, which tells the loop how to see when it is done; and an increment expression, which modifies any variables that need it. The following is a simple example:

For count = 0 To 100 Step 2
    document.write("Count is " & CStr(count) & "<br />")
Next

Note

The Cstr function converts a numerical value into a string.

In this example, the expressions are all simple numeric values—the initial value is 0, the ...

Get Platinum Edition Using XHTML™, XML, and Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.