<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>