由if转为switch语句的问题,很着急!~~

来源:百度知道 编辑:UC知道 时间:2024/05/21 00:45:23
dim struseragent
struseragent = request.servervariables("http_user_agent")
if (instr(struseragent,"Windows CE; PPC;")>0) then
response.redirect "ppc2003.aspx"
elseif(instr(struseragent,"Windows CE; Smartphone;")>0) then
response.Redirect "sp2003.aspx"
elseif(instr(struseragent,"Nokia6681")>0) then
response.Redirect "Symbian80.aspx"
elseif(instr(struseragent,"Nokia3230")>0) then
response.Redirect "Symbian70.aspx"
elseif(instr(struseragent,"Nokia6600")>0) then
response.Redirect "Symbian70.aspx"
elseif(instr(struseragent,"Mozilla")>0) then
response.Redirect "Palm54.aspx"
else
response.Redirect "unknow.

楼上说的不对!
if 转换成switch的条件是if语句只能是单独的if语句,而不能有else if.
比如if(条件1)
{
}
if(条件2)
{
}
可以转换成switch为:
switch(条件)
{
case 结果1:
执行语句1;
case 结果2:
执行语句2;
}
但要是if......else if......else if......else的if语句则不能转换成switch语句。

我不觉得上面程序嵌套太多,即使改用switch你看看能够少几行。这段代码确实很好读。

switch()
case

end
把每个if变成case就可以了