asp中不能用switch語(yǔ)句,要用select case語(yǔ)句了
簡(jiǎn)單的介紹一下
選擇報(bào)表的工作一樣,如果語(yǔ)句。然而不同的是,他們可以檢查多個(gè)值。當(dāng)然,你有
多個(gè)相同的,如果.. else語(yǔ)句,但是這并不總是最好的方法。
選擇語(yǔ)句允許一個(gè)程序來(lái)計(jì)算表達(dá)式,并試圖匹配表達(dá)式的值案件標(biāo)簽。如果找到匹
配,程序執(zhí)行相關(guān)的聲明。對(duì)于SELECT語(yǔ)句的語(yǔ)法如下:
select case expression
case label_1
statements_1
case label_2
statements_2
...
case else
statements_n
end select
該計(jì)劃首先查找與匹配的表達(dá)式的值標(biāo)簽的情況,然后條控制轉(zhuǎn)移到該條款,執(zhí)行相
關(guān)的聲明。如果沒(méi)有找到匹配的標(biāo)簽,程序查找任擇案Else子句,如果發(fā)現(xiàn),將控制
轉(zhuǎn)移到該條款,執(zhí)行相關(guān)的聲明。如果沒(méi)有Case Else子句發(fā)現(xiàn),程序繼續(xù)執(zhí)行的聲明
后選擇結(jié)束。利用休息時(shí)間,避免因進(jìn)入下一個(gè)代碼自動(dòng)執(zhí)行。
讓我們考慮一個(gè)例子:
%@ language="vbscript">
%
Dim Flower
Flower = "rose"
select case flower
case "rose"
response.write(flower " costs $2.50")
case "daisy"
response.write(flower " costs $1.25")
case "orchild"
response.write(flower " costs $1.50")
case else
response.write("There is no such flower in our shop")
end select
%>
例子1、
%
'/*ASP中用select case代替其他語(yǔ)言中的switch case, default用case else*/
dim today
today = 5
select case today
case 0
str = "星期天"
case 1
str = "星期一"
case 2
str = "星期二"
case 3
str = "星期三"
case 4
str = "星期四"
case 5
str = "星期五"
case 6
str = "星期六"
case 7, 8, 9
str = "today的值是7,8,或9"
case else
str = "未知"
end select
response.write str
response.End()
%>
/*------------輸出結(jié)果--------
星期五
------------*/
實(shí)例2、
board=request("board")
select case board
case "1"
boardName = "技術(shù)版"
case "2"
boardName = "信息版"
case "3"
boardName = "客服星空"
case "4"
boardName = "灌水區(qū)"
case "5"
boardName = "市場(chǎng)營(yíng)銷"
case "6"
boardName = "經(jīng)理論壇"
case "7"
boardName = "影音論壇"
case "8"
boardName = "延伸服務(wù)"
case "9"
boardName = "東北片區(qū)"
case "10"
boardName = "市場(chǎng)動(dòng)態(tài)"
case "11"
boardName = "群發(fā)交流"
case "12"
boardName = "hombre"
case "14"
boardName = "論壇"
case "15"
boardName = "在線答疑"
case else
boardName = "腳本之家"
end select
注意:case "1"后面不能有冒號(hào),boardName = "技術(shù)版"后面不能有分號(hào),而且不能出現(xiàn)break語(yǔ)句