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

"While" Statements

This section describes how 'While' statements work in VBScript. A block of statements is repeated as long as the specified condition is true.

Another type of loop statements is called "While" statement, which has the following syntax:

   While condition
      statement_block (multiple statements)
   Wend

where "condition" is a Boolean value.

A "While" statement is executed like this:

Step 1: Check Boolean value of "condition".

Step 2: If the current value of "condition" is "True", continue with Step 4.

Step 3: If the current value of "condition" is "False", terminate the loop.

Step 4: Execute "statement_block" enclosed in the "While ... Wend" loop.

Step 5: Continue with Step 1.

The logic of a "While" statement is simpler than a "For ... Next" statement. But you have to manage the condition carefully, so that its value will become "False" at some point to terminate the loop.

Notice that there seem to be no "Exit" statement to break "While" loop 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

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