ASP do While loop syntax and do while instance tutorial

Source: Internet
Author: User

After another common use of do while loops ... The loop of the next loop. Repeat a statement in a Do While loop statement

The number of blocks is uncertain. Repeated statements or when the condition is true or until the condition becomes true. The syntax looks like this:

do [while| Until] Condition
Statements
Loop

Todo
Statements
Loop [while| Until] Condition

In this case, the code within the loop will execute at least once. In one example:

The following example defines a loop, which begins with i = 0. The loop will continue to run as long as I am less than or equal to

10. I'm going to add 1 each time the loop runs.
Select Actionselect alltry it<%
Dim i ' use I as a counter
i = 0 ' Assign a value to I

Do While i<=10 ' Output of the values from 0 to 10
Response.Write (I & "<br >")
i = i + 1 ' increment the value of I for next time loop executes
Loop
%>
Now, let's consider a more useful example of creating a drop-down list for days, months or years. You can make

Use the code for this registration form, for example.

<%
' Creates an array
Dim Month_array (11)
Month_array (0) = "January"
Month_array (1) = "February"
Month_array (2) = "March"
Month_array (3) = "April"
Month_array (4) = "May"
Month_array (5) = "June"
Month_array (6) = "July"
Month_array (7) = "August"
Month_array (8) = "September"
Month_array (9) = "October"
Month_array (Ten) = "November"
Month_array (one) = "December"

Dim i ' use I as a counter

Response.Write ("<select name=" "Day" ">" & vbCrLf)
i = 1
Do While I <= 31
Response.Write ("<option value=" & I & ">" & I & "</option>" & VbCrLf)
i = i + 1
Loop
Response.Write ("</select>")

Response.Write ("<select name=" "Month" ">" & vbCrLf)
i = 0
Do While I <= 11
Response.Write ("<option value=" & I & ">" & Month_array (i) & "</option>"

& VbCrLf)
i = i + 1
Loop
Response.Write ("</select>")

Response.Write ("<select name=" "Year" ">")
i = 1900
Do Until i = 2005
Response.Write ("<option value=" & I & ">" & I & "</option>" & VbCrLf)
i = i + 1
Loop
Response.Write ("</select>")
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.