ASP/VBScript Do … Loop Repeats a block of statements while a condition is True or until a condition becomes True.
ShotDev Focus:
- Using Asp and Do … Loop
Syntax
Do [{While | Until} condition] [statements] [Exit Do] [statements] Loop Or, you can use this syntax: Do [statements] [Exit Do] [statements] Loop [{While | Until} condition]
The Do…Loop statement syntax has these parts:
Part | Description |
condition | Numeric or string expression that is True or False. If condition is Null, condition is treated as False. |
statements | One or more statements that are repeated while or until condition is True. |
Remarks
The Exit Do can only be used within a Do…Loop control structure to provide an alternate way to exit a Do…Loop. Any number of Exit Do statements may be placed anywhere in the Do…Loop. Often used with the evaluation of some condition (for example, If…Then), Exit Do transfers control to the statement immediately following the Loop.
When used within nested Do…Loop statements, Exit Do transfers control to the loop that is nested one level above the loop where it occurs.
Example
asp_do_loop.asp
<% Option Explicit %> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <% Dim i i = 1 Do While i <= 5 Response.write("www.ShotDev.Com<br>") i = i + 1 Loop Response.write("<hr>") i = 1 Do Response.write("www.ShotDev.Com<br>") i = i + 1 Loop While i <= 5 Response.write("<hr>") i = 1 Do Until i = 5 Response.write("www.ShotDev.Com<br>") i = i + 1 Loop Response.write("<hr>") i = 1 Do Response.write("www.ShotDev.Com<br>") i = i + 1 Loop Until i = 5 %> </body> </html>
Create a asp file and save to path root-path/myasp/
Run
http://localhost/myasp/asp_do_loop.asp
Screenshot