ASP中if语句、select 、while循环的使用方法

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title><%="页面标题"%></title>
</head>

<body>
<%="多条件判断"%>
<%
response.Write("<br />")
response.Write("利用response对象的Write方法输出地内容!")

%>
<br />
<%

dim a,b
a=200
b=300
response.Write("两数之和为:")
response.Write(a+b)
response.Write("<br />")
if a=100 then
response.Write("a=100,第一个条件满足。")
elseif a=200 then
response.Write("a=200,第二个条件满足。")
elseif a=300 then
response.Write("a=300,第三个条件满足。")
else
response.Write("三个条件都不满足。")
end if
%>
<%
response.Write("<br />")
dim textnumber
textnumber=200
select case textnumber
 case 100
 response.Write("数值为100, 条件满足!")
 case 200
 response.Write("数值为200,条件满足 !")
 case 300
 response.Write("数值为300 ,条件满足!")
 case else
 response.Write("以上条件,条件都不满足!")
 end select


%>
<%
response.Write("<br />")
dim i,sum
i=0
sum=0
 while i<=100
 sum=sum+i
 i=i+1
wend
response.Write("100以内所有整数的和为:")
response.Write(sum)
%>
<%
response.Write("<br />")
dim w,s
w=0
s=0
do 
s=s+w
w=w+1
loop while w<=100
response.Write("100之内的所有整数之和为:")
response.Write(s)
response.Write("<br/>")
response.Write("w的值是:")
response.Write(w)
%>

</body>
</html>

具体的介绍就不多说了,大家看下实例就可以了

考虑后期的便于阅读,yii666小编再为大家整理一下

asp if语句

①if A then B

②if A then文章地址https://www.yii666.com/blog/115132.html

B网址:yii666.com<

end if

③if A then

B

else

C网址:yii666.com

end if

④if A then文章来源地址:https://www.yii666.com/blog/115132.html

B

elseif C then

D

end if

⑤if A then文章来源地址https://www.yii666.com/blog/115132.html

B

elseif C then

D

else

E

end if

If....Then.....Else

在下面的情况中,您可以使用 If...Then...Else 语句:
在条件为 true 时,执行某段代码
选择两段代码之一来执行时
如果需要在条件为 true 时只执行一行语句,可以把代码写为一行:
if i=10 Then msgbox "Hello"
在上面的代码中,没有 .else.. 语句。我们仅仅让代码在条件为 true 时执行一项操作(当 i 为 10 时)。
假如我们需要在条件为 true 时执行不止一条语句,那么就必须在一行写一条语句,然后使用关键词 "End If" 来结束这个语句:

if i=10 Then
  msgbox "Hello"
  i = i+1
end If

在上面的代码中,同样没有 .else.. 语句。我们仅仅让代码在条件为 true 时执行了多项操作。
假如我们希望在条件为 true 时执行某条语句,并当条件不为 true 时执行另一条语句,就必须添加关键词 "Else":

if i=10 then
  msgbox "Hello"
else
  msgbox "Goodbye"
end If

当条件为 true 时会执行第一段代码,当条件不成立时执行第二段代码(当 i 不等于 10 时)。
If....Then.....Elseif
假如你希望选择多套代码之一来执行,可以使用if...then...elseif语句:

if payment="Cash" then
  msgbox "You are going to pay cash!"
 elseif payment="Visa" then
  msgbox "You are going to pay with visa."
 elseif payment="AmEx" then
  msgbox "You are going to pay with American Express."
 else
  msgbox "Unknown method of payment."
end If

Select Case
假如你希望选择多套代码之一来执行,可以使用 SELECT 语句:

select case payment
 case "Cash"
  msgbox "You are going to pay cash"
 case "Visa"
  msgbox "You are going to pay with visa"
 case "AmEx"
  msgbox "You are going to pay with American Express"
 case Else
  msgbox "Unknown method of payment"
end select

以上代码的工作原理:首先,我们需要一个简单的表达式(常常是一个变量),并且这个表达式会被做一次求值运算。然后,表达式的值会与每个 case 中的值作比较,如果匹配,被匹配的 case 所对应的代码会被执行。

版权声明:本文内容来源于网络,版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。文本页已经标记具体来源原文地址,请点击原文查看来源网址,站内文章以及资源内容站长不承诺其正确性,如侵犯了您的权益,请联系站长如有侵权请联系站长,将立刻删除

领支付宝红包赞助服务器费用

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信图片_20190322181744_03.jpg

微信扫一扫打赏

请作者喝杯咖啡吧~

支付宝扫一扫领取红包,优惠每天领

二维码1

zhifubaohongbao.png

二维码2

zhifubaohongbao2.png