Vbscript Do Until Loop

Updated on 20 Feb 2012,
Published on 31 Jul 2008

Vbscript Do until loop is almost similar to the vbscript do while loop that we learnt in the previous tutorial. Vbscript Do until loop works until the condition becomes true. Counter part increment or decrement is placed manually inside the do until loop. Vbscript do until loop also supports two types of syntaxes that can be used to execute the code block repeatedly until the condition becomes true.

Classic ASP VbScript Basics Examples:

You can see the live samples and examples of Classic ASP VbScript Basics from the following links:

Syntax for Vbscript Do Until Loop

Syntax 1
Do Until condtion [e.g. i = 5]
    'code to be executed
Loop
Syntax 2
Do
    'code to be executed
Loop Until condition [e.g. i = 5]

Syntax 1 for vbscript Do until loop shows that the code block will be executed until condition becomes true.

Syntax 2 for vbscript Do until loop shows that the code block will be executed at least one time even if the until condition returns true or false.

Examples of Vbscript Do Until Loop

<%
 
Dim count

count = 0

Do Until count = 5
    Response.Write count & "<br />"
    count = count + 1
Loop

Response.Write "********************************<br />"
Response.Write "Value of count after do while loop: " & count & "<br />"
Response.Write "---------------------------------<br />"

 
Do
    Response.Write count & "<br />"
    count = count + 1
Loop Until count = 10

%>

Note that vbscript do until loop exits the loop when condition becomes true. If loop condition does not get true then it goes out of range and throws an exception such as "Operation not Allowed".

Output:

You can see the output of above discussed code from the following link:

VbScript Do Until Loop in ASP

Continue to next tutorial: Vbscript If Then Else In ASP to learn about if else conditions.

0 Responses to "Vbscript Do Until Loop"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email