asp do while與while語句執行個體

來源:互聯網
上載者:User

<script language="vbscript" runat="server">
 sub chkfirstuntil()    '迴圈前檢查
  dim count,x
  count=0
  x=0
  do until x<10    'do…loop語句,當x<10 時執行
   count=count+1
   x=x+1
  loop     'do…loop 語句結束標誌
  response.write("<center>")  '顯示的文字中間對齊
  '顯示的文字
  response.write("do until...loop執行結果:程式執行<font color=red>"&count)
  response.write("</font> 次<br><br>") '<br>表示換行
 end sub
 sub chklastuntil()    '迴圈後檢查
  dim count,x    '聲明變數
  count=0     '初始設定變數
  x=0     '初始設定變數
  do     'do…loop 語句
   count=count+1   'count值加1
   x=x+1    'x值加1
  loop until x<10
  response.write("<center>")  '文字中間顯示
  '要顯示的文字
  response.write("do...loop until執行結果:程式執行<font color= red>"&count)
  response.write("</font> 次<br><br>")
 end sub
</script>
<html>
<head>
<title>do loop語句執行個體example21</title>
</head>
<body>
<%
 chkfirstuntil
 chklastuntil
%>
</body>
</html>

while語句執行個體

 

<%
 function checkletter(str)    'str 為要檢測的字串
  checkletter=true    '初始化
  letters="abcdefghijklmnopqrstuvwxyz"  '初始化
  for i=1 to len(str)    'len 函數返回字串長度
   'mid(str,i,1)返回字串str第i個字元,ucase函數將該字元轉換為大寫形式
   checkchar=ucase(mid(str,i,1))
   if (instr(letters,checkchar)<=0) then 'checkchar 在letters中不存在
    checkletter=false
    exit function   '跳出function 過程
   end if
  next      '結束for 迴圈
 end function
%>
<html>
<head>
<title>while wend執行個體example22</title>
</head>
<body>
<form method="post" action="example22.asp" name = form1>
 <p align="center">請輸入字串:<input type="text" name="string" size="20" value=<%=request.form("string")%>></p>
 <p align="center"><input type="submit" value="確定" name="submit"></p>
</form>
<%
 if request.form("submit")="確定" then
  str=request.form("string")         '讀取輸入的字串
  letters="abcdefghijklmnopqrstuvwxyz"    '初始化
  length=len(str)    '輸入的字串的長度
  i=1     '初始設定變數
  while i<length+1   'while迴圈
   'mid(str,i,1)返回字串str第i個字元,ucase 函數將該字元轉換為大寫形式
   checkchar = ucase(mid(str,i,1))
   if (instr(letters,checkchar)<=0) then 'checkchar 在letters中不存在
    '給出提示
    response.write("<script>alert('輸入的字串中存在非字母')</script>")
    response.end   '結束asp檔案的執行
   end if
   i=i+1
  wend      '結束while迴圈
 end if
%>
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.