在传统的ASP中,有没有办法提前从一个函数返回,而不是运行整个函数?例如,假设我有一个函数...
Function MyFunc(str)
if (str = "ReturnNow!") then
Response.Write("What up!")
else
Response.Write("Made it to the end")
end if
End Function
我可以这样写吗?
Function MyFunc(str)
if (str = "ReturnNow!") then
Response.Write("What up!")
return
end if
Response.Write("Made it to the end")
End Function
注意return语句,我当然不能在传统的ASP中这样做。有没有办法在返回语句所在位置中断代码执行?
发布于 2010-02-04 23:59:43
是的,使用exit function
。
Function MyFunc(str)
if str = "ReturnNow!" then
Response.Write("What up!")
Exit Function
end if
Response.Write("Made it to the end")
End Function
我通常在从函数返回值时使用它。
Function usefulFunc(str)
''# Validate Input
If str = "" Then
usefulFunc = ""
Exit Function
End If
''# Real function
''# ...
End Function
发布于 2010-02-05 00:02:02
在传统的ASP中,你需要使用Exit Function
Function MyFunc(str)
if (str = "ReturnNow!") then
Response.Write("What up!")
Exit Function
end if
Response.Write("Made it to the end")
End Function
https://stackoverflow.com/questions/2201072
复制相似问题