我的ASP经验之路(3)--VBScript的条件语句
这篇主要介绍Vbscript里的两个最常用的条件语句。
1、 if…then…else…end if
经常当我们编写代码时,我们需要根据不同的判断执行不同操作。我们可以使用条件语句完成这个工作。
(1)、当条件为True或False时,执行指定要运行的语句。例: <%
a=1 '定义变量a的值为1
If a=1 then response.write(\'当a=1时,写出\这里是单语句的写法,所以省略了后面的End if %>
或者你也可以这样写: <%
a=1 '定义变量a的值为1 If a=1 then
response.write(\ response.write(\end if %> (2),当条件为True或False时,分别运行不同的语句。例: <%
a=10 '定义变量a的值为1 if a>100 then
response.write(\大于100\elseif a>50 then
response.write(\大于50\elseif a>10 then
response.write(\大于10\else
response.write(\小等于10\end if
‘这里的运行结果是“小等于10” %>
2、 if…then…else…end if
Select Case 结构提供了 If...Then...ElseIf 结构的一个变通形式,可以从多个语句块中选择执行其中的一个。Select Case 语句提供的功能与 If...Then...Else 语句类似,但是可以使代码更加简练易读。例: <%
a=10 '定义变量a的值为1 select case a case 100
response.write(\等于100\ case 50
response.write(\等于50\
case 10
response.write(\等于10\end select
’运行结果为“等于10” %>
本文原创:义乌网站建设 http://www.15ask.com 写于 2012-03-29