asp do while 迴圈文法與do while執行個體教程

來源:互聯網
上載者:User

在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>")
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.