asp do while与while语句实例
asp教程 do while与while语句实例
<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>
- 上一篇:asp For Each语句实例
- 下一篇:asp Application