萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp編程 >> asp do while 循環語法與do while實例教程

asp do while 循環語法與do while實例教程

在do while循環的另一種常用後... Next循環的循環。在do while循環語句重復語句

塊的次數不定。重復的陳述或者當條件為真或直到條件變為True。語法如下所示:

Do [While|Until] condition
  statements
Loop

Do 
  statements
Loop [While|Until] condition

在這方面,這個循環內的代碼將執行至少一次的情況。在有一個例子:

下面的例子定義了一個循環,開始與i = 0。循環將繼續運行,因為我只要小於或等於

10。我將增加1每次循環運行。
Select ActionSelect AllTry It<%
Dim i 'use i as a counter
i = 0 'assign a value to i

Do While i<=10 'Output the values from 0 to 10
  response.write(i & "<br >")
  i = i + 1 'increment the value of i for next time loop executes
Loop
%>
現在,讓我們考慮一個更有用的例子,創建下拉幾天,幾個月或幾年清單。您可以使

用此登記表的代碼,例如。

<%
'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(10) = "November"
month_array(11) = "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>")
%>

copyright © 萬盛學電腦網 all rights reserved