VBScript Tutorials - Herong's Tutorial Examples - Version 5.20, by Dr. Herong Yang

"Do ... Loop" Statements

This section describes how 'Do ... Loop' statements work in VBScript. A block of statements is repeated based on the specified condition.

Personally, I think that two types of loops, "For ... Next" and "While", are enough for any loop programming situations. But the designers of VBScript decided to give us an extra type of loops, "Do ... Loop" statements, with the following different flavors:

1. "Do While ... Loop" Statements

   Do While condition
      statement_block
   Loop

They are identical logically to:

   While condition
      statement_block
   Wend

2. "Do Until ... Loop" Statements

   Do Until condition
      statement_block
   Loop

They are identical logically to:

   While Not condition
      statement_block
   Wend

3. "Do ... Loop While" Statements

   Do
      statement_block
   Loop While condition

They are identical logically to:

   statement_block
   While condition
      same_statement_block
   Wend

4. "Do ... Loop Until" Statements

   Do
      statement_block
   Loop Until condition

They are identical logically to:

   statement_block
   While Not condition
      same_statement_block
   Wend

I will leave it to you to write some sample scripts for "Do ... Loop" statements as exercises.

Note that VBScript offers "Exit Do" statements to allow you to terminate "Do ... Loop" statements early.

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

 Conditional Statements - "If ... Then" and "Select Case"

Loop Statements - "For", "While", and "Do"

 "For ... Next" Statements

 "For ... Next" Statement Example Examples

 "While" Statements

 "While" Statement Examples

"Do ... Loop" Statements

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)

 References

 Printable Copy - PDF Version

"Do ... Loop" Statements - Updated in 2015, by Dr. Herong Yang